Link to home
Start Free TrialLog in
Avatar of Lawrence Salvucci
Lawrence SalvucciFlag for United States of America

asked on

TRIM function in SQL

I'm converting some of my access queries to SQL but the TRIM function isn't part of SQL. How can I convert this to SQL then?

SOItemNo: Trim(Mid([fsokey],7,Len(Mid([fsokey],7))-3))

Open in new window

Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

You need to use LTRIM and RTRIM together. Also, replace MID with SUBSTRING:
LTrim(RTrim(Substring([fsokey],7,Len(Substring([fsokey],7))-3)))

Open in new window

Avatar of Lawrence Salvucci

ASKER

ok thank you. When I try to put that code in my query it says the "SUBSTRING' requires 3 arguments. Is there something missing for that function?
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland 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
I think there is some error in your access query

the mid function should have 3 arguments and in your access query there are only 2 arguments
>I'm converting some of my access queries to SQL
If you haven't done so already, check out my article on Migrating your Access Queries to SQL Server Transact-SQL, which covers exactly the road you're going down.  Good luck.