Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. DECLARE @itemvalues TABLE
  2. (
  3. item_id int,
  4. hasitem_values bit
  5. )
  6.  
  7. DECLARE @Cdoc int
  8.  
  9. Insert into @itemvalues
  10. select cf.item_id,1 from dbo.CoField cf
  11. join dbo.EdField ef on cf.edf_id = ef.edf_id
  12. where item_id in (select Distinct item_id FROM dbo.Comp
  13. WHERE (@id IS NULL OR (id = @id AND p_id IS NULL)) AND (@p_id IS NULL OR p_id = @p_id) )
  14. group by cf.item_id
  15. having count(0) > 0
  16.  
  17. IF(@id is not null)
  18. BEGIN
  19.  
  20. select @Cdoc =count(1) from dbo.Saveddoc
  21. where id = @id and [text] Is not NULL
  22. END
  23.  
  24. SELECT i.label, i.color, i.item_id, i.[start_date], i.end_date,
  25. sd.[text] as documentation,
  26. ISNULL(c.has_enddate, 0) enddate ,
  27. c.c_type
  28. FROM dbo.item i
  29. LEFT JOIN dbo.SavedDocumentation sd ON sd.item_id = c.item_id AND (@order_id IS NULL OR sd.order_id = @order_id)
  30. LEFT JOIN @itemvalues iv ON iv.item_id = c.item_id
  31. 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)
  32. ORDER BY CASE WHEN c.[order] IS NULL THEN 0 ELSE c.[order] END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement