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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.