我有一个存储过程,我必须仅在该记录的位字段为 0 的行上加入表。这可能吗?这是我拥有/需要的
SELECT TOP 100
SR.ServiceRecordID,
dbo.fn_ServiceRecordGetServiceName(SR.ServiceRecordID,''),
SR.LocationStd,
SR.AreaServedStd,
SR.RegionalLimited,
R.Region,
CASE WHEN (ISNULL(R_SR.RegionID,0) = 0 AND ISNULL(R_SR_Serv.RegionID,0) = 0)
THEN 0 ELSE 1 END AS Visible,
NULL
FROM ServiceRecord SR
INNER JOIN Sites S
ON SR.SiteID = S.SiteID
INNER JOIN Regions R
ON R.SiteID = S.SiteID
LEFT OUTER JOIN lkup_Region_ServiceRecord R_SR
ON R_SR.RegionID = R.RegionID
AND R_SR.ServiceRecordID = SR.ServiceRecordID
--and this is the additional join I need ONLY if RegionalLimited = 0
CASE WHEN SR.RegionalLimited = 0 THEN
LEFT OUTER JOIN lkup_Region_ServiceRecord_Serv R_SR_Serv
ON R_SR_Serv.RegionID = R.RegionID
AND R_SR_Serv.ServiceRecordID = SR.ServiceRecordID
END
WHERE SR.SiteID = @SiteID
AND R.RegionID % 100 != 0