WebsiteSpark

Showing posts with label END OF MONTH. Show all posts
Showing posts with label END OF MONTH. Show all posts

Tuesday, 10 April 2012

TSQL 2012 some new features

Here are some new features of TSQL 2012 demonstrated :
/**********
3 types of casting
**********/
SELECT TRY_PARSE('4000' as int) as CInt SELECT TRY_PARSE('4000a' as int) as CInt-- though TRY_CAST is not a recognized built in function name, it still worksSELECT TRY_CAST('4000' as int) as CInt SELECT TRY_CAST('4000a' as int) as CIntSELECT try_convert(int, '4000') as CIntSELECT try_convert(int, '4000a') as CInt 

Get End Of Month, given a date
******/
/*****SELECT EOMONTH(getdate());SELECT EOMONTH('2012-02-01'); 

Log function
*********/
/********-- Log to the base e also referred as lnSELECT Log(10) ;-- Log to the base 10 or any other numberSELECT Log(10,10) ;
Concatination
*********/
/********-- used instead of "+"SELECT Concat('Abcd', ' , ', 'efgh', ' - ', 'ijkl', ' + ', 'mnop', '....');-- major benifit of using Concat over "+"SELECT 'Abcd' + ' , ' + 'efgh' + ' - ' + 'ijkl' + null + ' + ' + 'mnop' + '....' ;-- Returns NULLSELECT Concat('Abcd', ' , ', 'efgh', ' - ', 'ijkl', null,' + ', 'mnop', '....');-- returns result eleminating NULL 
 
 
/*********
Culture sensitive date format
-- first param : calue
second param : d for date , t for time, '' for date time
third param culture info
for all the culture info, refer to
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(VS.80).aspx
**********/
select FORMAT(getdate(),'d','en-US')select FORMAT(getdate(),'d','hi')select FORMAT(getdate(),'d','en-GB')select FORMAT(getdate(),'d','kok')select FORMAT(getdate(),'d','sa-IN')select FORMAT(getdate(),'d','ta') select format( 199.991, '$0.00', 'en-GB');