日期:2014-05-17  浏览次数:20756 次

循环的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 v1
from table1
open curtable1
fetch next from curtable1 into @v1
while @@fetch_status = 0
begin
    exec(@v1)
    fetch next from curtable1 into @v1
end
close curtable1
deallocate curtable1