SQL Server (v)--common functions

Source: Internet
Author: User
Tags add time first string

1. Math function: Manipulate one data and return a result

--Take the upper limit ceiling

Select Code,name,ceiling (price) from car;

--Lower floor

Select Floor, from car

--abs Absolute Value

-Pi (), pi, brackets, no need to add anything.

--round Rounding Select ROUND (3.76,0)

--SQRT Open Radicals

--square squared, multiplied by himself

2. String functions:

--Convert capital Upper

Select Upper (pic) from car;

--Convert lowercase lower

--Go to Space select LTrim (' 123 ') to go left space

Select ' 123123 ' can be displayed directly without checking the data.

--space () put a few numbers inside, print out a few spaces

--left, similar to substring, intercepts select left (' 123456 ', 3) from the opening

--len, length

Select Len (' aaaaaa '); return several lengths

--replace replacement

Select replace (' aaaaabbaaaaa ', ' BB ', ' haha '); replace the BB in the first string with the haha

--reverse Flip

Select reverse (' abc '); The result is CBA

--String conversion function str

Select STR (1.567,3,1); Convert 1.567 to String, 3 for--up to 3 digits, one for decimal point, 1 for--reserved 1 digits after decimal point

--String intercept SUBSTRING

Select substring (' ABCDEFG ', 2, 3); Intercept 3 bits starting from 2nd, index starting from 1

3. Time-Date function:

--Get current system time GetDate ()

Select GETDATE ();

Sysdatetime () Gets the timestamp of the database service

--Get Month day

Select year (' 1999-1-1 ');

--Determine if the date is correct, isdate return bit

Select IsDate (' 2000-2-31 ') returns the bit type, False is 0,true is 1

--Add Time DateAdd

Select DATEADD (year,5, ' 2000-1-1 '); Add what type, plus how much, to who adds

--Returns the day of the week datename, the value returned is a string

Select Datename (Weekday, ' 2000-1-1 ');

Note: DatePart can return a few weeks, but the type of int is returned

You can also return the day of the week, by month

Select Datename (Day, ' 2000-1-1 ');

The first day of the year

Select Datename (dayofyear, ' 2000-1-1 ');

SQL Server (v)--common functions

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.