SQL Server Functions

SQL Server Functions


-- PARSE
 
 
SELECT PARSE('Monday, 13 December 2010' AS date USING 'en-GB') AS OrderDate,

PARSE('£345.98' AS money USING 'en-GB') AS OrderAmount




-- TRY_PARSE
 
 
SELECT TRY_PARSE('Monday, 32 December 2010' AS date USING 'en-US') AS OrderDate,

TRY_PARSE('£345.98' AS money USING 'en-US') AS OrderAmount


-- TRY_CONVERT
 
 
SELECT TRY_CONVERT(float, '1.2'), TRY_CONVERT(int, 'One')



 
 
-- DATEFROMPARTS
 
 
SELECT DATEFROMPARTS (2010, 12, 31)




--DATETIMEFROMPARTS
 
 
SELECT DATETIMEFROMPARTS ( 2010, 12, 31, 23, 59, 59, 0 )




--SMALLDATETIMEFROMPARTS
 
 
SELECT SMALLDATETIMEFROMPARTS ( 2010, 12, 31, 23, 59 )




--DATETIME2FROMPARTS
 
 
SELECT DATETIME2FROMPARTS ( 2010, 12, 31, 23, 59, 59, 1, 7 )




--TIMEFROMPARTS
 
 
SELECT TIMEFROMPARTS ( 23, 59, 59, 1, 5 )




--DATETIMEOFFSETFROMPARTS
 
 
SELECT DATETIMEOFFSETFROMPARTS ( 2010, 12, 31, 14, 23, 23, 1, 8, 0, 7 )

 
--EOMONTH
DECLARE @date DATETIME = GETDATE()
SELECT EOMONTH ( @date ) AS 'This Month',
  EOMONTH ( @date, 1 ) AS 'Next Month',
  EOMONTH ( @date, -1 ) AS 'Last Month'






-- CHOOSE
 

 
SELECT CHOOSE ( 3, 'Cash', 'Credit Card', 'Debit Card', 'Invoice' )

  

 --IIF
DECLARE @i int = 3
SELECT IIF(@i % 2 = 0, 'Even', 'Odd')

--CONCAT
SELECT CONCAT(Firstname, ' ', LastName) AS CustomerName
FROM InternetSales.dbo.Customers

--FORMAT
SELECT FORMAT(UnitPrice, 'C', 'en-GB')
FROM InternetSales.dbo.SalesOrderDetail

Comments

Popular posts from this blog

Calculating Age of the person in T-SQL

How to Troubleshoot Subscription issue in Reporting Services