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

关于存储过程的问题,恐怕要邹老师亲自出马了
下面是存储过程里的一些语句
select   @sCrmstr= 'select   scardno,nmoney   from   '+@sCrm+ '..kcardaccount   where   sCustomer_c= '+@sCustomer_c
exec   (@sCrmstr)
我想问下应该怎么把上面那取到的2个值   赋给变量@scardno,@nmoney?  
好麻烦,试了好多种方法都无效


------解决方案--------------------
select @sCrmstr= 'select @scardno=scardno,nmoney from '+@sCrm+ '..kcardaccount where sCustomer_c= '+@sCustomer_c
exec sp_executesql @sCrmstr,N@scardno varchar(1000) out

--类似这样,用sp_executesql
------解决方案--------------------
declare @scardno nvarchar(50),@nmoney nvarchar(50)
declare @sCrmstr nvarchar(4000)
declare @sCrm nvarchar(250),@sCustomer_c nvarchar(50)
select @sCrmstr= 'select @scardno=scardno,nmoney from '+@sCrm+ '..kcardaccount where sCustomer_c= '+@sCustomer_c
exec sp_executesql @sCrmstr,N '@scardnoint output ',@scardno output
select @scardno

------解决方案--------------------
exec sp_executesql @sql ,N@scardno varchar(1000) out ,@scardno out

--这样