我正在尝试将 FaxType 和 IsPackage 内部加入一列。一旦列被内部连接,我只想在 IsPackage = 1 时添加单词“Package”。
- RX 来自“FaxType 表”
- 包来自 IsPackage 表。
- packagetype 是临时列。我不确定我是否需要这个?
预期结果示例
packagetype = RX, Package
询问:
select 'DM' as FaxType, FaxId, RequestDate, FaxedTo, FaxNumber, Status, ExtendedStatus, StatusDate, UserName, IsPackage, DocumentId, -1 as PatientMedicationId, '' as Event, '-1' as NCPDPID, 0 as IsEPerscription, -1 as AccessionNumber,
Case When IsPackage = 0 then (Select FilePath from PatientDocument where DocumentId = fl.DocumentId and ( '443' = -1 or '443' = PatientId )) else (Select FilePath from dm_Package where fl.DocumentId = PackageId and ( '443' = -1 or '443' = PatientId )) End as Path,
Case When IsPackage = 0 then (Select LastFirstName from Patient p, PatientDocument pd where fl.DocumentId = pd.DocumentId and pd.PatientId = p.PatientId) else (select LastFirstName from Patient p, dm_Package pa where fl.DocumentId = pa.PackageId and pa.PatientId = p.PatientId) END
as LastFirstName, Case When IsPackage = 0 then (select [Description] from PatientDocument where fl.DocumentId = DocumentId and ( '443' = -1 or '443' = PatientId )) else (select PackageName from dm_Package where fl.DocumentId = PackageId and ( '443' = -1 or '443' = PatientId )) End
as [Description], '' as JobId, -1 as SeqNumber, '' as RefNumber, (select DocId from dbo.PatientDocument pd where fl.DocumentId = pd.DocumentId) as DocId
FROM dbo.dm_FaxLog fl