Code
SELECT
D.[SourceId]
,D.[RepCode]
,D.[SourceBus]
,D.[PolicyType]
,D.[Discount]
,D.[CommRate] as CommisionRate
,D.[SourceCode]
,D.[StartDate]
,D.[EndDate]
,D.[CreateDate]
,D.[CoverType]
,C.[ID]
,C.[CreditLimit]
,C.[CreateDate]
,C.[CreatedBy]
,C.[LastUpdatedDate]
,C.[UpdatedBy]
,C.[Email]
FROM [WBISCommon].[dbo].[WBIS_CommDisc] D,
[WBIS2].[dbo].[CreditLimit] C
Where
D.RepCode = C.RepCode AND
D.SourceCode = C.SourceCode AND
D.PolicyType = 'GTT' AND
D.CoverType in ('P','A') AND
D.SourceCode Like '%' + @pValue +'%'
OR D.SourceBus Like '%' + @pValue +'%'
AND not exists(select 1 from [WBISCommon].[dbo].[WBIS_CommDisc]
where RepCode=c.RepCode )
END
SELECT
D.[SourceId]
,D.[RepCode]
,D.[SourceBus]
,D.[PolicyType]
,D.[Discount]
,D.[CommRate] as CommisionRate
,D.[SourceCode]
,D.[StartDate]
,D.[EndDate]
,D.[CreateDate]
,D.[CoverType]
,C.[ID]
,C.[CreditLimit]
,C.[CreateDate]
,C.[CreatedBy]
,C.[LastUpdatedDate]
,C.[UpdatedBy]
,C.[Email]
FROM [WBISCommon].[dbo].[WBIS_CommDisc] D,
[WBIS2].[dbo].[CreditLimit] C
Where
D.RepCode = C.RepCode AND
D.SourceCode = C.SourceCode AND
D.PolicyType = 'GTT' AND
D.CoverType in ('P','A') AND
D.SourceCode Like '%' + @pValue +'%'
OR D.SourceBus Like '%' + @pValue +'%'
AND not exists(select 1 from [WBISCommon].[dbo].[WBIS_CommDisc]
where RepCode=c.RepCode )
END
关键在于 not exists(select 1 from [WBISCommon].[dbo].[WBIS_CommDisc]
where RepCode=c.RepCode )
起了过滤