TSQL Query syntax to MS Access syntax

Hi Experts,

I have this:
 "cnv" + Right('00'+Convert([nvarchar],[ID]),3)

Open in new window

for TSQL

But when I ran this:
 "cnv" & Right('00'+Convert([nvarchar],[ID]),3)

Open in new window

for Access

and got an error:
Undefined function 'Convert' in expression.

Not only do I need the convert but also need the proper syntax to do the same in Access.

Please help and thanks
Amour22015Asked:
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.

Mike EghtebasDatabase and Application DeveloperCommented:
In access:

"cnv" & Right("00"+Format([ID],"000"))
0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
If [ID] is just a numeric number that you need converted to string, then access will do that automatically and you can just write:
 "cnv" & Right('00'+[ID],3)
0
Rey Obrero (Capricorn1)Commented:
what is the result of this expression
 "cnv" + Right('00'+Convert([nvarchar],[ID]),3)  in TSQL?


in access try

"cnv00" & Right([ID],3)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ste5anSenior DeveloperCommented:
Just to clarify this:

 SELECT "cnv" + RIGHT('00' + CONVERT([NVARCHAR], [ID]), 3)
 FROM   ( VALUES ( 1234, 'TEST' ) ) Q ( ID, cnv );

Open in new window


Double quotation marks denote a column name in T-SQL. So you need in Access:

SELECT	[cnv] & Right("00" + [ID] , 3) 
 FROM	yourTable;

Open in new window

0
Amour22015Author Commented:
eghtebas I tried your answer and got a error: "The expression you entered has a function containing the wrong number of arguments.

Anders Ebro I tried your answer and got:  cnv2  I am looking for cnv002

Rey Obrero I tried your answer and got cnv002 But also got cnv0087 I am looking for cnv087

Please help and thanks
0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Examples make it much easier to understand where you are going. Try this
 "cnv" & Format([ID],"000")
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
Rey Obrero (Capricorn1)Commented:
try this



"cnv" & Format(Right([ID],3) ,"000")
0
Amour22015Author Commented:
ste5an I tried your answer and same as Anders Ebro but I also had to change [cnv] to "cnv" because I got a prompt for cnv.

Please help and thanks
0
Amour22015Author Commented:
Great both of these work fine
0
Rey Obrero (Capricorn1)Commented:
Format([ID],"000")  will return erroneous result if the ID is more than 3 digits
i.e.,

"cnv" & format(12345,"000")  will give you  cnv12345

so you need to get the three right most digits using the Right() function
0
Mike EghtebasDatabase and Application DeveloperCommented:
If you have ID = 12345, for example, the instead of using convert(varchar(10)...) as in tsql, in access use:

MsgBox Format(ID, "0000000000")      <-- 10 zeros

returns "0000012345"                           <-- 10 digits
0
ste5anSenior DeveloperCommented:
Then it is not T-SQL or you have some preprocessing going on here.
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
Query Syntax

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.