dm_unseen

Greatest/Least ivf

Apr 18th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.05 KB | None | 0 0
  1. CREATE FUNCTION [dbo].[ivf_least] (@1 datetime=null,@2 datetime = null ,@3 datetime = null,@4 datetime=null,@5 datetime = null)
  2. RETURNS TABLE WITH SCHEMABINDING
  3. RETURN
  4. (WITH coal(a1,a2,a3,a4,a5)
  5. AS (SELECT COALESCE(@1,@2,@3,@4,@5),COALESCE(@2,@3,@4,@5,@1),COALESCE(@3,@4,@5,@1,@2),COALESCE(@4,@5,@1,@2,@3),COALESCE(@5,@1,@2,@3,@4))
  6. SELECT case when a1<=a2 and a1<=a3 and a1<=a4 and a1<=a5 then a1  
  7. when a2<=a3 and a2<=a4 and a2<=a5 then a2
  8. when a3<=a4 and a3<=a5 then a3
  9. when a4<a5 then a4
  10. else a5 end as out from coal);
  11. GO
  12.  
  13. ALTER FUNCTION [dbo].[ivf_greatest] (@1 datetime=null,@2 datetime = null ,@3 datetime = null,@4 datetime=null,@5 datetime = null)
  14. RETURNS TABLE WITH SCHEMABINDING
  15. RETURN
  16. (WITH coal(a1,a2,a3,a4,a5)
  17. AS (SELECT COALESCE(@1,@2,@3,@4,@5),COALESCE(@2,@3,@4,@5,@1),COALESCE(@3,@4,@5,@1,@2),COALESCE(@4,@5,@1,@2,@3),COALESCE(@5,@1,@2,@3,@4))
  18. SELECT case when a1>=a2 and a1>=a3 and a1>=a4 and a1>=a5 then a1  
  19. when a2>=a3 and a2>=a4 and a2>=a5 then a2
  20. when a3>=a4 and a3>=a5 then a3
  21. when a4>a5 then a4
  22. else a5 end as out from coal);
  23. GO
Advertisement
Add Comment
Please, Sign In to add comment