日期:2014-05-16 浏览次数:20464 次
--ID selling_shop jbr chexing mark
--selling_shop jbr guize
update tbA a
set a.mark = (case when a.chexing like (case when b.guize = '%-%' then '%' else b.guize end)+'%' then 1 else 0 end)
from tbB b
where a.selling_shop = b.selling_shop and (a.jbr = (case when b.jbr = '%' then a.jbr else b.jbr end))
;with cte as (
select a.id,a.[selling_shop],a.jbr,a.chexing,CASE WHEN CHARINDEX(REPLACE(b.[guize],'%',''),a.[chexing] )>0 THEN 1 ELSE 0 END mark
from [A] LEFT JOIN [B] ON (a.[selling_shop]=b.[selling_shop] AND a.[jbr]=b.[jbr] )OR (a.[selling_shop]=b.[selling_shop] AND a.[jbr] LIKE b.[jbr])
)
update a
set a.mark=cte.mark
from cte where a.id=cte.id