Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Alter function [dbo].[Asd](@hid hierarchyid, @limit int)
  2. Returns xml
  3. With RTURNS NULL ON NULL INPUT
  4. BEGIN
  5. RETURN
  6. (
  7. Case when @ limit =0 then null
  8. ELSE
  9. (SELECT
  10. S.hid as "@hid",
  11. S.level as "@level",
  12. S.name as "@name",
  13. (Select
  14. R. Name as 'name',
  15. RTRIM(R.mobile) as 'mobile'
  16. From [dbo].[V_ACS_a] R
  17. Where s.hid=r.hid for xml path ('employee'), type) as 'employees',
  18. Case when @hid=s. Hid. GetAncestor(1) then [dbo].[Asd](s.hid, @limit - 1) end
  19. From [dbo].[Caompanystructure] s
  20. Where @hid =s.hid.GetAncestor(1) and Active=1
  21. For xml path('path'), type
  22. )
  23. End
  24. );
  25. End
  26.  
  27. RTRIM(R.mobile) as 'mobile'
  28.  
  29. NULLIF(R.mobile, '') as 'mobile'
  30.  
  31. declare @employees table (name varchar(20), mobile varchar(20))
  32. insert into @employees values
  33. ('Employee 1', '(123)456-78-90'),
  34. ('Employee 2', ' '),
  35. ('Employee 3', '')
  36.  
  37. select
  38. e.name as name,
  39. nullif(e.mobile, '') as mobile
  40. from @employees e
  41. for xml path('employee')
  42.  
  43. <employee>
  44. <name>Employee 1</name>
  45. <mobile>(123)456-78-90</mobile>
  46. </employee>
  47. <employee>
  48. <name>Employee 2</name>
  49. </employee>
  50. <employee>
  51. <name>Employee 3</name>
  52. </employee>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement