1

次のselectステートメントで列pa.NumberOfPagesを選択できるようにしたいと思います。dm_package paこれどうやってするの?

ステートメント 1 を選択

    SELECT 
Case When IsPackage = 1 then 'DM, Package' else 'DM' end 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

テーブル名dm_package pa

    pa.IsFax, pa.FaxName, pa.faxNumber, pa.FilePath, pa.DocRoot, pa.Note, pa.PatientId, 
    isnull(fl.ExtendedStatus,'') as FaxExtendedStatus, StatusDate as FaxStatusDate, pa.DocId, pa.NumberOfPages 
4

2 に答える 2

1

SQL でテーブルを結合する方法に精通していますか?

http://technet.microsoft.com/en-us/library/ms191517(v=sql.105).aspx

select a.data1, b.data2
from a_table a
join b_table b on a.data3 = b.data3
于 2013-08-08T20:54:35.063 に答える
1

dm_FaxLog と dm_package の FaxNumber は同じだと思います。それからあなたはすることができます -


SELECT f1.faxNumber, pa.NumberOfPages --list other required columns 
FROM   dm_FaxLog fl
INNER JOIN dm_package pa ON pa.faxNumber = f1.faxNumber

于 2013-08-08T21:02:36.217 に答える