1

我希望能够pa.NumberOfPagesdm_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

我假设 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 回答
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 回答