Tips in SQL Server (repeat, replace, intercept, remove spaces, number of digits after the decimal point)

Source: Internet
Author: User
Tags rtrim string back

PS: Essays written in SQL Server (repeat, replace, intercept, remove spaces, number of digits after the decimal point)

/*---------------------------Repeat--------------------------------*/--repeating string returns "Abc#abc#abc#"Select Replicate('abc#',3);/*---------------------------Replace--------------------------------*/--Substitution string replaces E with E to return "Abcedef"--Replace (' string ', ' Replace text before ', ' replace text ')Select Replace('Abcedef','e','E');--Specify location substitution string to return "Heabcworld"--stuff (' string ', where to start replacing, replacing several, ' characters to replace ')Select Stuff('Hello World',3,4,'ABC');/*----------------------------Intercept--------------------------------*/--Intercept string Return "A, AB, Wrold"--subString (' string ', where to start interception, interception of several)Select subString('ABC',1,1),subString('ABC',1,2),subString('Hello Wrold',7,5);--take the left string back to "Left,leftstr"--left (' string ', which starts with a few from the Ieft)Select  Left('leftstring',4);Select  Left('leftstring',7);--take the right string back to "string,ing"--right (' string ', start with a few from the left)Select  Right('leftstring',6);Select  Right('leftstring',3);/*---------------------------go to the space----------------------------------*/--Remove left spaceSelect LTrim('ABC'),LTrim('# abc#'),LTrim('ABC');--Remove the right spaceSelect RTrim('ABC'),RTrim('# abc#'),RTrim('ABC');/*-------------------------the number of digits after the decimal point----------------------------*/--Use the function round (value, s), where s represents the number of decimal digitsSELECT ROUND(4.994,2)--back to 4.990--cast with function (value as numeric (n,s)), where n is the number of significant digits and s represents the number of decimal digitsSELECT CAST(4.994  asNumericTen,2))--Search returns 4.99--Convert with function (numeric (n,s), numeric), where n is the number of significant digits, s represents the number of decimal digitsSELECT CONVERT(Numeric (Ten,2),4.9852222)--Back to 4.99

Tips in SQL Server (repeat, replace, intercept, remove spaces, number of digits after the decimal point)

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.