SQL Cheat Sheet: String Functions (SQL Server / T-SQL)
Messy text is everywhere: names in the wrong case, phone numbers full of brackets, codes with missing zeros.
This 2-page cheat sheet gives you ready-to-use T-SQL to search, slice, mask and tidy text in SQL Server.
What’s inside
Trim any characters, not just spaces
Search from a position, or by pattern
Capitalise names properly
Clean up phone numbers by stripping brackets, dashes, dots and spaces in one go
Ignore accents when comparing text
Pull the first number out of a piece of text
Strip leading zeros, on any version of SQL Server
Split a full name into first and last names
Pad with leading zeros
Get the text after the last delimiter
Count how often a character appears
Pick the Nth item from a list with STRING_SPLIT
Mask an email address, keeping the first letter and the domain
Fill in a message template
Quote and escape text to make it safe for SQL or JSON
Find unwanted characters, plus handy extras like character codes and sound-alike matching
Who it’s for?
Analysts and developers cleaning or formatting text in SQL Server
Anyone preparing customer data for reports or exports
Office workers moving from Excel to SQL
Format
A 2-page A4 PDF, ready to print or keep open on a second screen.
Every query uses the same example tables, so you can follow along easily.
Want all four cheat sheets?
Get the SQL Cheat Sheet Power Pack and save 37%.
For personal use only.
From Rosleecia Productions.