SQL 实现在每个Items类中增加一栏

本文介绍了一个使用SQL Server游标和存储过程的示例代码,该示例展示了如何通过游标遍历特定表中的记录,并对每条记录进行操作,包括更新字段值等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

declare @Items nvarchar(200),
       @Number nvarchar(10),
       @orderID nvarchar(50),
       @Title nvarchar(100),
       @notice nvarchar(max),
       @Site nvarchar(10)
declare cur_items cursor for
select distinct Items   from [MROPRDB].[dbo].[C_Notice] 
open cur_items
fetch cur_items into @Items
while @@fetch_status=0
begin
select @Number=t2.Number,@orderID=t2.orderID,@Title=t2.Title,@notice=t2.notice,@Site=t2.Site
 from  [C_Notice] as t2  where Items=@Items and orderID=(SELECT  max(cast(orderID as int)) from [C_Notice] where
Items=@Items and )
insert into [C_Notice](Id,Number,orderID,Title,notice,Author,Site,MainBody,YNUPDATE,YNVIEW,CreateTime,Items) values(3000,@Number,@orderID+1,@Title,@notice,'keivin.cai',@Site,'<div></div>',1,0,getdate(),@Items)
fetch cur_items into @Items
end
close cur_items
deallocate cur_items
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值