Common SqlServer built-in functions and usage

Source: Internet
Author: User

Common SqlServer built-in functions and usage

Select cast ('2014/1/03 'as datetime );

Select convert (varchar (10), GETDATE (), 120); -- convert to date type

Select case when id = 1 THEN 'a0 'else 'TT' END from demo1; -- case when

Select len ('ssa Edison ') -- returns 6 bytes

Select left ('sea', 2) -- se starts from the left with the first two characters

Select right ('sea', 2) -- aa two characters from the right

Select LTRIM ('ds') -- remove the left space Rtrim () to remove the right space

Select replace ('I hate you', 'hate', 'love') -- return I love you

Select STUFF ('test do it', 2, 4, 'hh') -- parameter description 1 original string 2 start position 3 end position 4 replace string

Select GETDATE (), GETUTCDATE ()

Select DATEDIFF (dd, GETDATE (), cast ('1970-03-27 'as datetime) -- returns the difference between two dates.

Select DATEADD (mm, 12, getdate (); -- specifies the abbreviation dd-day mm-month wk-week for adding a day or month.

Select DATENAME (dd, GETDATE () -- returns the string format of the specified part of the date.

Select abs (-12) -- returns the absolute value of the corresponding number

Select CEILING (4.2) -- 5 returns the smallest integer greater than or equal to the expression

Select floor (4.2) -- 4 returns the maximum integer less than or equal to the expression

Select power (2, 4) -- indicates the power 4 of 2

Select sign (-12) ---1 returns 1 negative for an integer and-1 0 returns 0

Select sqrt (25) -- 5 square root

Select ROUND (5.4, 0.1) -- rounding to the specified precision

Select REVERSE ('abc') -- CBA REVERSE output

Select substring ('dest0w', 2, 4); -- truncates four digits from the second

Select REPLICATE ('sa ', 3) -- repeated expression

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.