Solved

MAX and IIF statements Access vs SQL

Posted on 2013-06-27
3
693 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
Comment Utility
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
Comment Utility
Thanks I forgot about the case statement
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
Comment Utility
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now