SQL Server Common built-in functions and usage

Source: Internet
Author: User
Tags datetime getdate square root string format

SQL Server Common built-in functions and usage

Select cast (' 2012/02/03 ' as DateTime);

Select CONVERT (varchar, GETDATE (), 120);--Convert to date type

Select Case when ID =1 THEN ' A0 ' ELSE ' TT ' "from Demo1;--case '

Select Len (' SSA Edison ')--Returns 6 length

Select Left (' Seaa ', 2)--se from the top two characters

Select Right (' SEAA ', 2)--aa two characters from the right-hand side

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

Select replace (' I hate ', ' hate ', ' love ')--return I love to You

Select STUFF (' Test do it ', 2,4, ' hh ')--parameter Description 1 primitive string 2 start position 3 End position 4 Replace string

Select GETDATE (), getUTCDate ()

Select DATEDIFF (Dd,getdate (), cast (' 2001-03-27 ' as datetime)--Returns the difference between two dates

Select DATEADD (Mm,12,getdate ()); --Make the addition of the day or month, such as shorthand Dd-day mm-month Wk-week

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 an expression

Select Floor (4.2)--4 returns the largest integer less than or equal to an expression

Select Power (2,4)--represents 2 of the 4-time side

Select sign ( -12)---1 return 1 negative for integer return-1 0 return 0

Select sqrt (25)--5 square root

Select ROUND (5.4,0.1)--rounded to specified precision

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

Select substring (' dese0w ', 2,4); --cut four bits from the second start

Select REPLICATE (' sa ', 3)--Repeat 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.