我想从这个动态 sql 中删除引号,所以它只是一个脚本。
set @sqlDNB= '
SELECT DISTINCT
Null CustomerID
,EntityID MCVID
,business_name CustomerName
,physical_City + ',' + physical_state + '' + cast(physical_zip as varchar(7)) Address
,'' RM
,'' SubGroup
,'' HierarchyType
,'' status
,DNB.dunsnum DunsNumber
,'DNB' Source
from SOR.T_DunAndBradstreet DNB with (nolock)
left outer join SOR.T_McvDuns MCVDUNS with (nolock)
on DNB.dunsnum = MCVDUNS.DunsNumber
+
case
when @p_SearchMethod ='BeginsWith' and @p_CustomerName !='' then 'and business_name like ''' + @p_CustomerName + ''' '
when @p_SearchMethod ='Contains' and @p_CustomerName !='' then 'and Contains (business_name,''"' + @p_CustomerName + '"'')'
when @p_SearchMethod ='Exact' and @p_CustomerName !='' then 'and business_name =''' + @p_CustomerName + ''' '
else
''
end
+ ' where not exists
(select dunsnumber from sor.T_Customer customer where customer.DUNSnumber = DNB.dunsnum '
+
case
when @p_SearchMethod ='BeginsWith' and @p_CustomerName !='' then 'and customer.Name like ''' + @p_CustomerName + ''' '
when @p_SearchMethod ='Contains' and @p_CustomerName !='' then 'and Contains (customer.Name,''"' + @p_CustomerName + '"'')'
when @p_SearchMethod ='Exact' and @p_CustomerName !='' then 'and customer.Name =''' + @p_CustomerName + ''' '
else
''
end
if @p_TIN_SSN !=''
begin
set @sqlDNB = @sqlDNB + ' and customer.TINorSSN =''' + @p_TIN_SSN + ''' '
end
if @p_CustomerID !=''
begin
set @sqlDNB = @sqlDNB + ' and customer.[MCVID] =''' + cast(@p_CustomerID as varchar(20)) + ''' '
end
set @sqlDNB = @sqlDNB + ')'