Read about sql server charindex last occurrence, The latest news, videos, and discussion topics about sql server charindex last occurrence from alibabacloud.com
The string lookup feature has recently been used frequently.
Including
1. Full matching Find string
2. Fuzzy Lookup string
Both the CHARINDEX and PATINDEX functions return the start position of the specified pattern. PATINDEX can use wildcard
DECLARE @s VARCHAR (100)SET @s= ' r1-1-1 ' gets the number after the last "-"SelectREVERSE(@s) return value: 1-1-1R reverses the character. SelectLEN(@s) return value: 6 Get length SelectCHARINDEX(‘-‘,REVERSE(@s)) Return value: 2--Gets the position
Generally use fuzzy query, everyone will think like
SELECT * FROM table where a like '% character% 'If a SQL statement uses multiple like fuzzy queries and a large number of record bars, it must be slow.The following two methods can also implement
DECLARE @s VARCHAR (100)SET @s= ' r1-1-1 ' gets the number after the last "-"SelectREVERSE(@s) return value: 1-1-1R reverses the character. SelectLEN(@s) return value: 6 Get length SelectCHARINDEX(‘-‘,REVERSE(@s)) Return value: 2--Gets the position
SQL statement
Copy Code code as follows:
Reverse (substring reverse (path), 1,charindex ('/', reverse (path))-1)
How SQL takes out the character to the right of the last special character in a string, for example: 10*20*300, how do
SQL statement
Copy codeThe Code is as follows: reverse (substring (reverse (Path), 1, charindex ('/', reverse (Path)-1 ))
How can I retrieve the right character of the last special character in a string, for example, 10*20*300? How can I get 300?
First build a test sheet: CREATE table teststring (name nvarchar (100));INSERT INTO teststringValues(' Zhang San, John Doe, Harry, Caifan, Xiao Rambler, Royal Palace '); 1. Determine the number of occurrences of a character (string) in a string, the
String functionsIn developing T-SQL, it is often necessary to perform a variety of operations on strings, and the following describes commonly used string functions. 1. ASCII ASCII code to get charactersThe ASCII code is the standard encoding of
First build a test sheet:Create Table nvarchar (+)); Insert into teststring Values (' Zhang San, John Doe, Harry, Caifan, Xiao Rambler, royal palace ');1. Determine the number of occurrences of a character (string) in a string, the position where
Several functions (Stored Procedures) that are useful but not commonly used (or with unclear details) are found during SQL server usage ):
Isnumeric, isdate, patindex, newid, collate, sp_executesql, checksum
Write it down for future query. Do
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.