Left Trim in SQL

Left Trim - Hello I am wanting to Left Trim a field in a SQL Table. Are you able to provide the script?

The Table is called Transheaders and the data field is called ExtraText

Thanks.
jspcAsked:
Who is Participating?
 
ste5anSenior DeveloperCommented:
Nope, you need to cast the column first. LTRIM() does not accept TEXT typed strings.

p.s. tag your such posts as either T-SQL or SQL Server and always post your used version.
0
 
ste5anSenior DeveloperCommented:
SQL Server/T-SQL:

See LTRIM() and T-SQL string functions:

SELECT LTRIM(T.ExtraText) AS TrimmedExtraText
FROM   Transheaders T;

Open in new window


In MySQL: See string functions. It's also LTRIM().

And same for Oracle/PL-SQL (LTRIM()).
0
 
jspcAuthor Commented:
Get this error:

Msg 8116, Level 16, State 1, Line 1
Argument data type text is invalid for argument 1 of ltrim function.
0
 
ste5anSenior DeveloperCommented:
Well, TEXT is a deprecated data type (since years). And most string functions cannot work on it. Cast it to the correct data type. In this case NVARCHAR(MAX).

SELECT LTRIM(CAST(T.ExtraText AS NVARCHAR(MAX))) AS TrimmedExtraText
FROM   Transheaders T;

Open in new window

p.s. why do you use still TEXT?
0
 
jspcAuthor Commented:
Do you think this would work?

UPDATE TRANSHEADERS SET ExtraText = LTRIM(ExtraText)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.