+ -
当前位置:首页 → 问答吧 → 询问一个存储过程的写法

询问一个存储过程的写法

时间:2011-11-24

来源:互联网

SQL code

alter procedure usp_ReplaceSourceText
(
    @t1 nvarchar(max)
)
as
declare @sql nvarchar(max)
begin
    set @sql='select ''update a
    set a.source_text=b.new
    from ''+name+'' a,'+@t1+' b
    where a.source_text=b.old;'' from sys.tables where name like ''%_transdb'''
    exec(@sql)
end


执行结果是:
update a set a.source_text=b.new from aa_transdb a,t1 b where a.source_text=b.old;
update a set a.source_text=b.new from ab_transdb a,t1 b where a.source_text=b.old;
...

想要的结果是把上面的结果在存储过程里直接执行了。
不知道我有没有说明白,就是上面的存储过程里动态生成了SQL语句,然后想把生成的SQL语句也一起执行了。这样存储过程该怎么写?返回值什么的应该怎么写才能看出执行的效果?谢谢

作者: bashen1101   发布时间: 2011-11-24

那把语句写进去不就完事了?

作者: qianjin036a   发布时间: 2011-11-24