首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

exec sp_executesql 有关问题

2012-03-08 
exec sp_executesql 问题表如下id arg1 arg2 arg3 comreslut1123@arg1+@arg23arg1-arg3是参数com 是表达式

exec sp_executesql 问题
表如下
id arg1 arg2 arg3 com reslut 
1 1 2 3 @arg1+@arg2 3
arg1-arg3是参数
com 是表达式
代码如下
declare @in_arg1 as int,@in_arg2 int ,@in_arg3 int
select @in_arg1 =arg1 ,@in_arg2=arg2 ,@in_arg1=arg3 from com where id =1;

declare @sql nvarchar(4000)
set @sql='select com from com where id=1; ';

exec sp_executesql
@stmt=@sql,
@params = n'@arg1 as int,@arg2 as int ,@arg3 as int,@result int output',
@arg1=@in_arg1 ,
@arg2=@in_arg2,
@arg3=@in_arg3
错误
总是提示
消息 102,级别 15,状态 1,第 9 行
'@arg1 as int,@arg2 as int ,@arg3 as int,@result int output' 附近有语法错误。
无法解决啊!!!
不好意思分很少了一点心意!!

[解决办法]
declare @in_arg1 as int,@in_arg2 int ,@in_arg3 int,@result int
select @in_arg1 =arg1 ,@in_arg2=arg2 ,@in_arg1=arg3 from com where id =1;

declare @sql nvarchar(4000)
select @sql='select @result='+com from com where id=1;

exec sp_executesql
@stmt=@sql,
@params = N'@arg1 as int,@arg2 as int ,@arg3 as int,@result int output',
@arg1=@in_arg1 ,
@arg2=@in_arg2,
@arg3=@in_arg3,
@result=@result output
select @result

热点排行