elena1234

Code to create user defined function ( T-SQL )

Mar 27th, 2022 (edited)
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.39 KB | None | 0 0
  1. --Code to create user defined function:
  2.  
  3. CREATE FUNCTION dbo.ufnCurrentDate()
  4.  
  5. RETURNS DATE
  6.  
  7. AS
  8.  
  9. BEGIN
  10.  
  11.     RETURN CAST(GETDATE() AS DATE)
  12.  
  13. END
  14.  
  15.  
  16. --Query that calls user defined function
  17.  
  18. SELECT
  19.        SalesOrderID
  20.       ,OrderDate
  21.       ,DueDate
  22.       ,ShipDate
  23.       ,Today = dbo.ufnCurrentDate()
  24.  
  25. FROM AdventureWorks2019.Sales.SalesOrderHeader A
  26.  
  27. WHERE YEAR(A.OrderDate) = 2011
  28.  
Add Comment
Please, Sign In to add comment