日期:2014-05-18  浏览次数:20570 次

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