Previously, I wanted to record some of the usual functions of SQL, but it has not been implemented ... Hey...
Until today, the substring () function is used, and in C # The starting value of this method is 0, and the starting value in SQL is 1. Silly points are not clear ...
This blog as a function of the use of SQL records, think of where to use where to write where ...
SubString (): the method used to intercept the specified string. The method has three parameters:
Parameter 1: Used to specify the string to manipulate.
Parameter 2: Used to specify the starting position of the string to intercept, with a starting value of 1.
Parameter 3: Used to specify the length to intercept.
Select substring (' abcdef ', 1,3)- -Return to Abcselect substring (' 123456321 ', 0,2)- -return 1, first place, best not to do so
Left (): returns the portion of the specified length in the given string. The method has two parameters:
Parameter 1: Used to specify the string to manipulate.
Parameter 2: Used to specify the length of the substring to be returned.
Select Left (' abc123 ', 3) --Returns Abcselect to left (' right side portion ', 4) --Returns
Right (): used to return the portion of the specified length in the given string. The method has two parameters:
Parameter 1: Used to specify the string to manipulate.
Parameter 2: Used to specify the length of the substring to be returned.
Select Right (' abc123 ', 3) --Return 123select to right (' left side portion ', 4)- -Return part
CharIndex (): used to return the starting position where the specified substring appears in the specified string. Returns 0 if it is not found. The method has two parameters:
Parameter 1: Used to specify the string to be searched.
Parameter 2: Used to specify a string to use as a retrieval.
Select CHARINDEX (' A ', ' 123a123 ')- -Returns 4select charindex (' abc ', ' 123a123 ')- -Returns 0select charindex (' abc ', ' 123abc123 ') --Return 4
Stuff (): used to delete a specified length of character and insert a new character/value at the location of the deletion. The method has four parameters:
Parameter 1: Used to specify the string to manipulate.
Parameter 2: Used to specify the starting position of the character to be deleted.
Parameter 3: Used to specify the length of the character to be deleted.
Parameter 4: Used to specify the new string/value to insert at the location of the deletion.
Select Stuff (' 123abc456 ', 4,3, ' ABC ')- -return 123abc456select stuff (' 123abc456 ', 1,3, ')- -Return to abc456, replace with empty string
How to use SQL Server common functions (continuous update)