游标update供应商经营范围

来源:互联网 发布:c语言头文件什么用 编辑:程序博客网 时间:2024/04/27 22:24
------update 供应商经营范围。循环从abc中把供应商的所有证照存在一个字段里面。
--------从字典值里面取值
declare @ProductName nvarchar(50)  
declare pcurr cursor for select gysbh from abc group by gysbh
open pcurr  
fetch next from pcurr into @ProductName  
while (@@fetch_status = 0)  
begin  
 --print (@ProductName) 
 DECLARE @cont varchar(1000)

SET @cont = ''

--拼接为字符串

SELECT @cont=@cont+ISNULL(b.DICTVALUE, '')+',' 
FROM abc a
left join DICTDOC b on a.gcategory = b.DICTLIST and b.FDNAME = 'gcategory'
WHERE gysbh = @ProductName
update a set a.businesscont = @cont
from BUSINESSDOC a
join SUPPLYDOC b on a.BusinessId = b.SuppliersId
join abc c on b.gysbh = c.gysbh
where c.gysbh = @ProductName and a.Is_Supp = 'Y'
--print (@cont)
 fetch next from pcurr into @ProductName  
end  
close pcurr
deallocate pcurr 
------------------------------end
-----------ceshi 测试
--declare @ProductName nvarchar(50)
--declare pcurr cursor for select ProductName from Products
--open pcurr
--fetch next from pcurr into @ProductName
--while (@@fetch_status = 0)
--begin
 --print (@ProductName)
 --fetch next from pcurr into @ProductName
--end
--close pcurr
--deallocate pcurr