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
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.

Mike EghtebasDatabase and Application DeveloperCommented:
In access:

"cnv" & Right("00"+Format([ID],"000"))
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)
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)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

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
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Examples make it much easier to understand where you are going. Try this
 "cnv" & Format([ID],"000")

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")
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
Amour22015Author Commented:
Great both of these work fine
Rey Obrero (Capricorn1)Commented:
Format([ID],"000")  will return erroneous result if the ID is more than 3 digits

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

so you need to get the three right most digits using the Right() function
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
ste5anSenior DeveloperCommented:
Then it is not T-SQL or you have some preprocessing going on here.
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.