这可能很简单,但我没有看到。我收到以下 SQL 的错误消息
Incorrect syntax near the keyword 'if'
。
DF.IsBillingEntity
是一个位列。
select OBS_CC.OBSVALUE 'Cost Center'
,U.LASTNAME 'Staff Lastname'
,U.FIRSTNAME 'Staff Firstname'
,U.LOGINNAME 'Staff Login'
,if (DF.IsBillingEntity = 1)
select 'Billable';
else
select 'Not Billable';
,DF.Suffix 'Credentials'
,OBS_SUP.OBSVALUE 'Supervisor'
,D.SUMMARY 'Note Name'
,D.DB_CREATE_DATE 'Date Created'
,dbo.Convert_ID_to_date(D.PUBTIME) 'Note Signed'
from DOCUMENT D
left join OBS OBS_CC on OBS_CC.SDID = D.SDID and OBS_CC.HDID=75246
left join PatientProfile P on D.SDID = P.SSDID
left join OBS OBS_SUP on OBS_SUP.SDID=D.SDID and OBS_SUP.HDID=711437
inner join USR U on D.USRID=U.PVID
left join DoctorFacility DF on U.PVID=DF.PVId
where OBS_SUP.OBSVALUE is not null
and dbo.cusExcludeRecords(P.PID,U.PVId) = -1
order by 1,2,3,6
我认为您需要 CASE(或某些 RDBMS 的 IIF)而不是 IF。 IF用于流量控制,不能用作列表达式。请参阅如何在 SQL SELECT 中执行 IF...THEN?