Link to home
Start Free TrialLog in
Avatar of jspc
jspcFlag for Australia

asked on

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.
Avatar of ste5an
ste5an
Flag of Germany image

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()).
Avatar of jspc

ASKER

Get this error:

Msg 8116, Level 16, State 1, Line 1
Argument data type text is invalid for argument 1 of ltrim function.
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?
Avatar of jspc

ASKER

Do you think this would work?

UPDATE TRANSHEADERS SET ExtraText = LTRIM(ExtraText)
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial