Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error around If Clause

Posted on 2007-10-05
4
Medium Priority
?
149 Views
Last Modified: 2010-03-19
I have a query that is throwing a comma error around my if clause. What am I missing??

SELECT p.ID as PatientID,
p.MedicalNumber as MRN,
p.LastName,
p.FirstName,
p.Status,
p.Age,
p.Sex as Gender,
p.AdmitDate,
p.DischargeDate,
p.AdmittingDiagnosis as Diagnosis,
loc.Abbreviation as CurrentLocation,
loc.PatientUnit as CurrentUnit
FROM Patient p
LEFT JOIN Location loc on loc.ID= Iif(p.HomeLocation is null,p.Destination,p.HomeLocation)
ORDER BY p.LastName,p.FirstName
0
Comment
Question by:NickMalloy
4 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20023068
well for starters a typical iif in tsql looks like

case when ... then ... else ... end
0
 
LVL 12

Expert Comment

by:weareit
ID: 20023077
LEFT JOIN Location loc on loc.ID= Iif(p.HomeLocation is null,p.Destination,p.HomeLocation)

Is it supposed to be Iif or If, or is this a typo???

-saige-
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 20023202
SELECT p.ID as PatientID,
p.MedicalNumber as MRN,
p.LastName,
p.FirstName,
p.Status,
p.Age,
p.Sex as Gender,
p.AdmitDate,
p.DischargeDate,
p.AdmittingDiagnosis as Diagnosis,
loc.Abbreviation as CurrentLocation,
loc.PatientUnit as CurrentUnit
FROM Patient p
LEFT JOIN Location loc on loc.ID= CASE WHEN  p.HomeLocation IS NULL THEN  p.Destination ELSE p.HomeLocation END
ORDER BY p.LastName,p.FirstName
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 20023342
SELECT p.ID as PatientID,
p.MedicalNumber as MRN,
p.LastName,
p.FirstName,
p.Status,
p.Age,
p.Sex as Gender,
p.AdmitDate,
p.DischargeDate,
p.AdmittingDiagnosis as Diagnosis,
loc.Abbreviation as CurrentLocation,
loc.PatientUnit as CurrentUnit
FROM Patient p
LEFT JOIN Location loc
on loc.ID= coalesce(p.homelocation,p.Destination)
ORDER BY p.LastName,p.FirstName
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

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