当前位置 : 主页 > 数据库 > mssql >

sqlserver 游标的简单示例

来源:互联网 收集:自由互联 发布时间:2021-04-05
Declare @Id varchar(20) Declare @Name varchar(20) Declare Cur Cursor For select substring(id,0,7) as id,name from temp1 Open Cur Fetch next From Cur Into @Id,@Name While @@fetch_status=0 Begin Update temp Set [c3]=@Name where [id] like @Id+
Declare @Id varchar(20)
Declare @Name varchar(20)
Declare Cur Cursor For
select substring(id,0,7) as id,name from temp1
Open Cur
Fetch next From Cur Into @Id,@Name
While @@fetch_status=0
Begin
Update temp Set [c3]=@Name where [id] like @Id+'%'
Fetch Next From Cur Into @Id,@Name
End
Close Cur
Deallocate Cur
网友评论