こんにちは、cTL列の値を取得するためにサブクエリを実行していますが、正しい応答のためにサブクエリの外側の列の値が必要ですが、SC変数とRC変数を認識しないというエラーが発生します。逃げ道はありますか?
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