0

FaxType と IsPackage を 1 つの列に内部結合しようとしています。列が内部結合されたら、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
4

1 に答える 1

0

IsPackage = 1 の場合は「DM、パッケージ」、そうでない場合は「DM」が FaxType として終了

于 2013-08-08T20:17:13.350 に答える