Solved

Access query with IIF into SQL

Posted on 2001-08-14
3
298 Views
Last Modified: 2006-11-17
I have an existing query in Access that I need to get into SQL server. The query has an immediate if. SQL does not seem to use the IIF function. How might I write this in SQL?

SELECT MtgReg.MtgID, MtgReg.RegNum, HStatus.HStatusName, IIf(HStatus.HStatusName<>"Reserved",Null,Sum(([MtgHInv].[RmRate]*(DateDiff("d",[ADate],[DDate]))))) AS HotelCost FROM .....
0
Comment
Question by:susantrider
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6384403
replace the IIF by CASE statements:

SELECT MtgReg.MtgID, MtgReg.RegNum, HStatus.HStatusName,
case when HStatus.HStatusName<>"Reserved" then Null
     else Sum(([MtgHInv].[RmRate]*(DateDiff("d",[ADate],[DDate])) ))
AS HotelCost FROM .....

Cheers
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 6384405
further corrections:


SELECT MtgReg.MtgID, MtgReg.RegNum, HStatus.HStatusName,
case when HStatus.HStatusName<>'Reserved' then Null
    else Sum(([MtgHInv].[RmRate]*(DateDiff(day,[ADate],[DDate])) ))
AS HotelCost FROM .....

Cheers

0
 

Author Comment

by:susantrider
ID: 6384448
angellll, This worked for me. Thanks!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

776 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