Declare @Id as integer
Declare @Id1 as integer
declare cursor_table cursor for
select id from #Data_get1
open cursor_table
fetch next from cursor_table into @id
while(@@fetch_status=0)
begin
set @id1 = @id
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id1) where id=@id1
end
Close cursor_table
DEALLOCATE cursor_table 我就是想循环 cursor_table 中的记录,一条一条地循环下来,可以得到每一条记录的id, 用以id 去更新另一个临时表的记录,请帮忙以上好象不对!请高手指正,谢谢!
Declare @Id1 as integer
declare cursor_table cursor for
select id from #Data_get1
open cursor_table
fetch next from cursor_table into @id
while(@@fetch_status=0)
begin
set @id1 = @id
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id1) where id=@id1
end
Close cursor_table
DEALLOCATE cursor_table 我就是想循环 cursor_table 中的记录,一条一条地循环下来,可以得到每一条记录的id, 用以id 去更新另一个临时表的记录,请帮忙以上好象不对!请高手指正,谢谢!
解决方案 »
- Microsoft OLE DB Provider for SQL Server ���� '80040e14' 出错了
- !!reporting service 怎么实现用+号点击显示、隐藏该行所属信息????
- 关于mssql数据库同步问题
- public 存储过程里的exec 权限问题
- 求一句SQL语句?在现在时间的基础上减一年
- 使用SqlServer Management执行数据库脚本后找不到创建的表
- 如何操作动态的列
- 关于临时表对象名无效?
- 如何用sql语句修改sqlserver数据库结构?
- Sql Sever2012 无法创建窗口是什么情况啊?
- 连接数据库登录程序
- 将Float转换为数据类型numeric时发生算术溢出错误
while(@@fetch_status=0)
begin
set @id1 = @id
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id1) where id=@id1
--至少你要加入以下语句避免死循环
fetch next from cursor_table into @id
end
Declare @Id1 as integer
declare cursor_table cursor for
select id from #Data_get1
open cursor_table
fetch next from cursor_table into @id
while(@@fetch_status=0)
begin
set @id1 = @id
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id1) where id=@id1
fetch next from cursor_table into @id
end
Close cursor_table
DEALLOCATE cursor_table
语句导致你不能取到下一条记录。在第一条记录上死循环了
--楼主可以这样不用 游标,不会锁表,效率也很高declare @Rows int,
@Row int,
@ID int
set @Row = 1
declare @t table(
Row int identity(1,1) not null,
Id int not null
)insert into @t
select id from #Data_get1
set @Rows = @@ROWCOUNT
while(@Row <=@Rows)
begin
select @id = id from @t where Row = @Row
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id) where id=@id
set @row = @row + 1
end
declare @Rows int,
@Row int,
@ID int
set @Row = 1
declare @t table(
Row int identity(1,1) not null,
Id int not null
)insert into @t
select id from #Data_get1
set @Rows = @@ROWCOUNT
while(@Row <=@Rows)
begin
select @id = id from @t where Row = @Row
print @ID
--update #Data_get2 set replyzsl = (select count(1) from test where id2=@id) where id=@id
set @row = @row + 1
end