Solved

MAX and IIF statements Access vs SQL

Posted on 2013-06-27
3
798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 41

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

730 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