Solved

Access query with IIF into SQL

Posted on 2001-08-14
3
300 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
[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
  • 2
3 Comments
 
LVL 143

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 143

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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