嗨我正在做一個子查詢來獲取cTL列的值但是我需要子查詢中的外列值爲正確的響應 但我得到錯誤,它不能識別SC和RC變長。任何出路?在子查詢中使用OuterQuery列
SELECT DISTINCT(cStoreCode) as SC
,cRetailerCode as RC
, cStoreCode + ' - ' + cStoreName AS Store,
x.TeamLead
FROM
(
SELECT cTL as TeamLead
FROM tblEmpSchedule
WHERE cRepCode LIKE @repCode AND
cClientCode LIKE @gCode AND
cProjectCode LIKE @pCode AND
cYear LIKE @year AND
cCycleNo LIKE @cycleNo AND
cRetailerCode LIKE @retailerCode AND
cStoreCode = SC AND
cRetailerCode = RC
)x
,tblEmpSchedule
WHERE cRepCode LIKE @repCode AND
cClientCode LIKE @gCode AND
cProjectCode LIKE @pCode AND
cYear LIKE @year AND
cCycleNo LIKE @cycleNo AND
cRetailerCode LIKE @retailerCode AND
cStoreCode <> '' AND cStoreCode is Not Null
ORDER BY cStoreCode
這沒有任何意義。您正在嘗試在您的FROM子句子查詢WHERE子句中使用SC/RC列很久之前,您已在您的SELECT列表中定義它們(發生在FROM和WHERE子句之後的***之後)。我甚至無法弄清楚你在這裏做什麼。 – RBarryYoung 2012-07-13 17:41:15
目前尚不清楚你想達到什麼樣的,你想與你的查詢解決什麼問題,那就是,爲什麼只是tblEmpSchedule一個簡單的查詢未返回所需的結果集。如果你能詳細說明,有人可以提供幫助。 (請參閱我發佈的答案以獲取更多詳細信息。) – spencer7593 2012-07-13 21:04:27