SQL Server String Manipulations

SQL Server String Manipulations:

We can use simple regular expressions for "LIKE" to filter as wild card characters.We can use [0-9] for digits and [a-z] for characters.
Eg: to filter a 4 digit ZIP code we can use " where ZIP like '[0-9][0-9][0-9][0-9]'"
      to filter the string that starts with digit we can use " where name like '[0-9]%'"

Like same, we can use ^ for the not match condition and _ for matching one character condition.
Eg: to filter names that don't start with p then we can use " where name like '[^p]%'"
      to filter names that end with ir then we can use " where name like '_ir'"

We can find the index of any character in a string expression with CHARINDEX function. To find the last index of any character, we can use the below...

datalength(filename)-charindex('.',reverse(filename),1)

Comments

Popular posts from this blog

Base 64 encoding and decoding

LINQ Queries with GROUP BY, INNER JOIN, COUNT and SUM: Examples

How to write Custom delete Confirmation Modal for Kendo Grid in MVC: