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

Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?

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

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.

Vitor MontalvãoMSSQL Senior EngineerCommented:
You need to use LTRIM and RTRIM together. Also, replace MID with SUBSTRING:

Open in new window

Lawrence SalvucciInformation Technology ManagerAuthor Commented:
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?
Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes, The 2nd Substring needs an argument. Should be the length of the string?

Open in new window

Please verify the parenthesis since I don't know the logic of your formula.

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
Vikas GargAssociate Principal EngineerCommented:
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
Jim HornMicrosoft SQL Server Data DudeCommented:
>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.
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
Microsoft SQL Server

From novice to tech pro — start learning today.