当前位置: 代码迷 >> Sql Server >> 存储过程 参数怎么取到值
  详细解决方案

存储过程 参数怎么取到值

热度:26   发布时间:2016-04-24 10:57:10.0
存储过程 参数如何取到值

declare @a varchar(20),@sql varchar(200)
 set  @sql=N'select'+ @a+'='+'Phone from House where Phone=''13902273189'''
exec(@sql)
select @a


--Phone是表的字段 :这段代码要怎么写,@a输出才有值 ? N'select'+ @a+'='+'Phone from House where Phone=''13902273189'''

------解决方案--------------------
declare @a varchar(20),@sql nvarchar(200)
 set  @sql=N'select  @a  ='+' name from sysobjects where id = 2007678200'
EXECUTE sp_executesql @sql , N'@a varchar(20) OUTPUT' , @a = @a OUTPUT
PRINT @a 

/*结果
sp_DTA_wkld_analysis
*/

------解决方案--------------------

declare @a varchar(20),@sql Nvarchar(200)
 set  @sql=N'select @a =Phone from House where Phone=''13902273189'''
exec sp_executesql @sql,N'@a varchar(30) output ',@a output
select @a

  相关解决方案