Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @itemvalues TABLE
- (
- item_id int,
- hasitem_values bit
- )
- DECLARE @Cdoc int
- Insert into @itemvalues
- select cf.item_id,1 from dbo.CoField cf
- join dbo.EdField ef on cf.edf_id = ef.edf_id
- where item_id in (select Distinct item_id FROM dbo.Comp
- WHERE (@id IS NULL OR (id = @id AND p_id IS NULL)) AND (@p_id IS NULL OR p_id = @p_id) )
- group by cf.item_id
- having count(0) > 0
- IF(@id is not null)
- BEGIN
- select @Cdoc =count(1) from dbo.Saveddoc
- where id = @id and [text] Is not NULL
- END
- SELECT i.label, i.color, i.item_id, i.[start_date], i.end_date,
- sd.[text] as documentation,
- ISNULL(c.has_enddate, 0) enddate ,
- c.c_type
- FROM dbo.item i
- LEFT JOIN dbo.SavedDocumentation sd ON sd.item_id = c.item_id AND (@order_id IS NULL OR sd.order_id = @order_id)
- LEFT JOIN @itemvalues iv ON iv.item_id = c.item_id
- WHERE (@id IS NULL OR (c.id = @id AND c.p_id IS NULL)) AND (@p_id IS NULL OR c.p_id = @p_id)
- ORDER BY CASE WHEN c.[order] IS NULL THEN 0 ELSE c.[order] END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement