Q:

How to Specify Trim Chars in SQL TRIM

I'm having a table Employee, in that some values are started with ", ". So, I need to remove the comma and white-space at the beginning of the name at the time of SELECT query using LTRIM() - SQL-Server.
My Table : Employee
CREATE TABLE Employee
(
PersonID int,
ContactName varchar(255),
Address varchar(255),
City varchar(255)
); 

INSERT INTO Employee(PersonID, ContactName, Address, City)
VALUES ('1001',', B. Bala','21, Car Street','Bangalore'); 

SELECT PersonID, ContactName, Address, City FROM Employee

Here the ContactName Column has a value ", B. Bala". I need to remove the comma and white-space at the beginning of the name.

A:

Alas, SQL Server does not support the ANSI standard functionality of specifying the characters for LTRIM().
In this case, you can use:
(case when ContactName like ', %' then stuff(ContactName, 1, 2, '')
      else ContactName
 end)

A:

You could potentially use PATINDEX() in order to get this done.
DECLARE @Text VARCHAR(50) = ', Well Crap';

SELECT STUFF(@Text, 1, PATINDEX('%[A-z]%', @Text) - 1, '');

This would output Well Crap. PATINDEX() will find first letter in your word and cut everything before it.
It works fine even if there's no leading rubbish:
DECLARE @Text VARCHAR(50) = 'Mister Roboto';

SELECT STUFF(@Text, 1, PATINDEX('%[A-z]%', @Text) - 1, '');

This outputs Mister Roboto
If there are no valid characters, let's say ContactName is , 9132124, :::, this would output NULL, if you'd like to get blank result, you can use COALESCE():
DECLARE @Text VARCHAR(50) = ', 9132124, :::';

SELECT COALESCE(STUFF(@Text, 1, PATINDEX('%[A-z]%', @Text) - 1, ''), '');

This will output an empty string.

