如何根据采购次数改变标志位????????????????
首先根据采购表和采购明细表统计出当月所采购的物品及其次数
select distinct productID as PID,count(*) as times -- into #tempfrom pordersub inner join porder on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID
select distinct productID as PID,case when count(1) > 1 then 1 else 0 end as isporder -- into #tempfrom pordersub inner join porder on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID
[解决办法]
update p set isporder=case when times>1 then 'true' else 'false' endfrom product p,(select distinct productID as PID,count(*) as times -- into #tempfrom pordersub inner join porder on pordersub.porderID = porder.porderID where datediff(month,porder.updatetime,getdate()) =0 group by productID) twhere t.productID =p.productID