954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using IF ISNUMERIC inside SELECT statement

Hello,

I am currenrtly trying to write a query in Microsoft Access 2010.

This query retreives a list of values from a table I have called tblTable

Some of the values are numeric and some are alpha numeric.

I am trying to do the query so that when it comes across numeric values, it places a 'Z' at the beginning of it.

If it is alpha numeric, the value is returned as it is.

I have made an attempt so far...but I keep getting an error message saying 'Missing Expression'.

My code is as follows:

SELECT PaperNo, IF( ISNUMERIC(PaperNo) = 1) THEN "Z" + PaperNo ELSE PaperNo
FROM tblTable


Can anybody help and advise on what I am doing wrong at all please?

Many Thanks,

Dan

dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Sorry, I meant that I get an error saying: 'Missing Operator'.

Dan

dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Okay, a couple of things going on here. First off, the IsNumeric operator returns 0 for false and -1 for true. You might consider using the MSAccess constant "True".

That being said, the proper syntax for a conditional in MSAccess SQL is the "IIF" function, rather than an IF...THEN construct. Your expression should then look something like this:

SELECT tblTable.PaperNo, IIf(IsNumeric([PaperNo])=True,"Z"+[PaperNo],[PaperNo]) AS Expr1
FROM tblTable;

Hope that solves your issue!

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

Hello,

Yeah that did solve it...thank you very much!

dwinn
Junior Poster in Training
53 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: