我下面的SQL查詢SQL NOT EXISTS查詢
declare @temp table(RevisionStatus varchar(100),DocTypeID varchar(50))
insert into @temp(RevisionStatus,DocTypeID)
select distinct md.RevisionStatus,dt.DocumentTypeID
from MissingDesignData md inner join tblDocumentType dt on md.[Doc Type]=dt.DocumentType inner join tblRevisionStatus rv on md.RevisionStatus=md.RevisionStatus
select distinct tm.RevisionStatus,tm.DocTypeID as 'DocType'
from @temp tm
rv.RevisionStatus=tm.RevisionStatus and rv.DocType=tm.DocTypeID
where not exists (select distinct rss.RevisionStatus,rss.DocType from tblRevisionStatus rss)
我需要返回的記錄,其中在tblRevisionStatus表不存在,但在@temp存在table.currently其返回空數據集
當我選擇@temp數據是如下
RevisionStatus DocType
PEN - Pending 14
PEN - Pending 16
PEN - Pending 2
PEN - Pending 3
PEN - Pending 30
PEN - Pending 34
PEN - Pending 5
PEN - Pending 55
tblRevisionStatus數據集回報
RevisionStatus DocType
IFC - Issued For Construction 4
RFD - Revised As Denoted 4
IFU - Issued For Use 4
AB - As Built NULL
C1 - Proceed, No Exception Taken 2
PEN - Pending 1
PEN - Pending 2
HLD - HOLD (Implementation Study ONLY) 1
當我運行上面給出的SQL查詢返回nothing.but只有
PEN - Pending 2
在tblRevisionStatus表中存在的記錄,爲什麼查詢不返回其他records.am我失去了一些東西?
ohh.i修正,但仍處於最後的結果相同result.no數據集 – chamara 2011-12-17 07:34:57