What are character manipulation functions in SQL Sever Give some examples
Loading
What are character manipulation functions in SQL Sever Give some examples
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nikhil PatilRank #385 · 6.5K reputationPosted Aug 16, 2025, 12:38 PM EDT
In SQL Server, character manipulation functions are built-in string functions that allow you to manipulate, search, and transform character (string) data. These functions are especially useful when dealing with text-based data stored in
CHAR,VARCHAR,NCHAR, orNVARCHARcolumns.1.
LEN()– Get the length of a string (number of characters)SELECT LEN('SQL Server') AS Length; -- Output: 102.
LTRIM()andRTRIM()– Remove leading or trailing spacesSELECT LTRIM(' Hello') AS NoLeadingSpaces; -- Output: 'Hello' SELECT RTRIM('Hello ') AS NoTrailingSpaces; -- Output: 'Hello'Pankajkumar PatelRank #181 · 13.4K reputationPosted Aug 18, 2025, 2:23 AM EDT
Hi Kiran Kumar,
Character manipulation functions are used to modify, extract, analyze string data, etc. Useful when working with textual data in queries, reports, stored procedures, etc.
Following are common character manipulation functions in SQL Server:
Examples:
SELECT LEN('Pankaj Patel') AS Length;-- Output: 12 SELECT LEFT('Pankaj Patel', 6) AS FirstName;-- Output: Pankaj SELECT RIGHT('Pankaj Patel', 5) AS LastPart;-- Output: Patel SELECT SUBSTRING('Pankaj Patel', 8, 5) AS LastName;-- Output: Patel SELECT CHARINDEX('Patel', 'Pankaj Patel') AS Position;-- Output: 8 SELECT REPLACE('Hello World', 'World', 'SQL') AS ReplacedText;-- Output: Hello SQL SELECT LTRIM(' Hello') AS NoLeadingSpaces; SELECT RTRIM('Hello ') AS NoTrailingSpaces; SELECT UPPER('sql server') AS UpperCase;-- Output: SQL SERVER SELECT LOWER('SQL SERVER') AS LowerCase;-- Output: sql server SELECT REPLICATE('*', 5) AS Stars;-- Output: ***** SELECT REVERSE('SQL') AS Reversed;-- Output: LQSHope this will help you!