SQL Server Mastery----built-in functions from getting Started

Source: Internet
Author: User
Tags getdate mathematical functions

--Supplement to aggregate functions--var to find the variance of a column--Mathematical Functions    Select ABS(-1)--Absolute Value    Select CEILING(3.5)    Select  Floor(3.5)    Select round(3.5555,2)        Select SQRT(4)    Select Square(2)    Select POWER(2,3)    Select RAND()* ---Date-time functions    Select Current_timestamp  --2015-09-09 22:53:12.727    Select GETDATE()--2015-09-09 22:55:02.980    SelectgetUTCDate ()--2015-09-09 14:55:54.867-World Standard Time        SELECT  Year(GETDATE())    SELECT MONTH(GETDATE())    SELECT  Day(GetDate())    SELECT Datename( Year,Getdate())--returns a string representing the specified date part of a specified date    SELECT Datename(WEEKDAY,Getdate())--Wednesday    --DATEADD (datepart, number, date) --returns a new datetime value that is added to the specified date after a time interval.  SELECT DATEADD(Week,1,GetDate())--date plus one week after the current date--DATEDIFF (datepart, StartDate, EndDate)--returns the number of date boundaries and time boundaries across two specified dates. SELECT DATEDIFF( Year,'2006-10-11','2006-11-01')--returns 0--conversion of date functions--CommonSelect CONVERT(varchar( -),GETDATE(), +)--2006-05-16 10:57:47.157Select CONVERT(varchar( -),GETDATE(), -)--2006-05-16 10:57:47.250Select CONVERT(varchar( -),GETDATE(), -)--2006-05-16 10:57:47Select CONVERT(varchar( -),GETDATE(), the)--20060516Select CONVERT(varchar( -),GETDATE(),121)--2006-05-16 10:57:49.700Select CONVERT(varchar( -),GETDATE(), -)--2006-05-16 10:57:49Select CONVERT(varchar( -),GETDATE(), at)--2006-05-16Select CONVERT(varchar( -),GETDATE(),102)--2006.05.16Select CONVERT(varchar( -),GETDATE(), -)--10:57:46:967Select CONVERT(varchar( -),GETDATE(), -)--10:57:47--String FunctionsSelect ASCII('a')--Convert to ASCII codeSelect Char( $)--convert ASCII integer to character ASelect  Left('ABCDEFG',3)--left-Most 3 string ABCSelect  Right('ABCDEFG',3)--right-most 3 stringsSelect Len('ABCDEFG')--number of returned strings 7Select Lower('AAaaa')--uppercase to lowercase aaaaaSelect Upper('AAaaa')--AAAAASelect Len(LTRIM('AAA a'))--Go left blank 5Select Len(RTRIM('AAA a'))--go to right space 7Select nchar( the)--return Unicode charactersSelect REPLACE('ABCDA','a','BBB')--Replace A with the BBB bbbbcdbbbSELECT STR(1234.56,6,1 )--counting starting from 1SELECT STUFF('abcdef',2,3,'IJKLMN')--AijklmnefSelect SUBSTRING('FSDFSD',2,2) SD----Type conversionSelect CAST('123'  as int)--123Select CONVERT(int,'123')--123Select CAST(123.4  as int)--123Select CONVERT(int,123.4)--123Select CAST('123.4'  as int)Select CONVERT(int,'123.4')--Conversion failed when converting the varchar value ' 123.4 ' to data type int.Select CAST('123.4'  as decimal)--123Select CONVERT(decimal,'123.4')--123Select CAST('123.4'  as decimal(9,2))--123.40Select CONVERT(decimal(9,2),'123.4')--123.40

SQL Server Mastery----built-in functions from getting Started

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.