Solved

MAX and IIF statements Access vs SQL

Posted on 2013-06-27
3
754 Views
Last Modified: 2013-06-29
I have an Access query with the following clause:

Max(IIf([dbo_AbsDrgDiagnoses]![DiagnosisSeqID]=1,[dbo_AbsDrgDiagnoses]![Diagnosis],0)) AS PrinDiag

I have translated it to SQL as:

MAX(iif(dbo.AbsDrgDiagnoses.DiagnosisSeqID=1,dbo.AbsDrgDiagnoses.Diagnosis,0)) as PrinDiag

I am getting a syntax error that "error in list of function arguaments: "=" not recognized

Do you see what could be wrong?

Thanks

Glen
0
Comment
Question by:GPSPOW
3 Comments
 
LVL 14

Expert Comment

by:mds-cos
ID: 39283234
According to MSDN for SQL 2012, what you have should work for the new IIF function.  But since it is not, give the CASE statement a try instead:

SELECT (CASE WHEN dbo.AbsDrgDiagnoses.DiagnosisSeqID = 1 THEN dbo.AbsDrgDiagnoses.Diagnosis ELSE 0) as PrinDiag
0
 

Author Comment

by:GPSPOW
ID: 39283238
Thanks I forgot about the case statement
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 39286300
just for completeness, correcting the syntactial errors in mds-cos's query.
SELECT MAX(CASE WHEN dbo.AbsDrgDiagnoses.DiagnosisSeqID = 1 THEN dbo.AbsDrgDiagnoses.Diagnosis ELSE 0 END) as PrinDiag

Open in new window

0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question