Link to home
Start Free TrialLog in
Avatar of NickMalloy
NickMalloyFlag for United States of America

asked on

Error around If Clause

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
Avatar of SQL_SERVER_DBA
SQL_SERVER_DBA
Flag of United States of America image

well for starters a typical iif in tsql looks like

case when ... then ... else ... end
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-
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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