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

LVL 1
Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?
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:
LTrim(RTrim(Substring([fsokey],7,Len(Substring([fsokey],7))-3)))

Open in new window

0
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?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes, The 2nd Substring needs an argument. Should be the length of the string?
LTrim(RTrim(Substring([fsokey],7,Len(Substring([fsokey],7,Len([fsokey])))-3)))

Open in new window

Please verify the parenthesis since I don't know the logic of your formula.
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
Vikas GargBusiness Intelligence DeveloperCommented:
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
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>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.
0
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.

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.