Guest User

Untitled

a guest
Jul 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43
  2. Copyright (c) Microsoft Corporation Express Edition with Advanced Services (64-bit) on
  3. Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
  4.  
  5. GO
  6. ALTER FUNCTION [dbo].[GetRoot]
  7. (
  8. @Param1 int
  9. )
  10. RETURNS varchar(50)
  11. AS
  12. BEGIN
  13. DECLARE @ReturnValue varchar(50)
  14. with results as
  15. (
  16. select parentouid,net_ouid from net_ou where net_ouid=@Param1
  17. union all
  18. select t2.parentouid,t2.net_ouid from net_ou t2
  19. inner join results t1 on t1.parentouid = t2.net_ouid where t2.parentouid <> t1.net_ouid
  20. )
  21. select @ReturnValue = net_ou.displayname
  22. from NET_OU RIGHT OUTER JOIN
  23. results ON net_ou.net_ouid = results.ParentouID where results.parentouid=results.net_ouid
  24.  
  25. RETURN @ReturnValue
  26.  
  27. END
  28.  
  29. ;with results as
  30. (
  31. select parentouid,net_ouid from net_ou where net_ouid=@Param1
  32. union all
  33. select t2.parentouid,t2.net_ouid from net_ou t2
  34. inner join results t1 on t1.parentouid = t2.net_ouid where t2.parentouid <> t1.net_ouid
  35. )
  36.  
  37. ;with results as
  38. (
  39. select parentouid,net_ouid from net_ou where net_ouid=@Param1
  40. union all
  41. select t2.parentouid,t2.net_ouid from net_ou t2
  42. inner join results t1 on t1.parentouid = t2.net_ouid where t2.parentouid <> t1.net_ouid
  43. )
  44. select @ReturnValue = net_ou.displayname
  45. from NET_OU RIGHT OUTER JOIN
  46. results ON net_ou.net_ouid = results.ParentouID where results.parentouid=results.net_ouid
  47.  
  48. RETURN @ReturnValue
  49.  
  50. END
Add Comment
Please, Sign In to add comment