当前位置: 代码迷 >> Sql Server >> 循环的sql指令如何写
  详细解决方案

循环的sql指令如何写

热度:147   发布时间:2016-04-25 01:20:05.0
循环的sql指令怎么写
我有一数据表!
table1
里面有多条记录
其中有一字段v1
v1里面保存的是字段计算指令

我想实现打开数据表table1
然后循环读取v1
执行v1的内容

select * from table1 
while ....
@v1=select v1 from table
exec(@v1)
.....

完整的sql应该怎么写


------解决方案--------------------
SQL code
declare @v1 varchar(2000)declare curtable1 cursor  for select v1from table1open curtable1fetch next from curtable1 into @v1while @@fetch_status = 0begin    exec(@v1)    fetch next from curtable1 into @v1endclose curtable1deallocate curtable1
  相关解决方案