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)