嗨,我正在做一个子查询来获取 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