declare @sql nvarchar(1000),@idname varchar(100)
set @sql=N'select @aa=idname from table where id='+@id
exec sp_executesql @sql,N'@aa varchar(100) output',@idname output
select @idname 结果
declare @sql nvarchar(1000),@idname varchar(100)
set @sql=N'select @aa=idname from table where id='+@id
exec sp_executesql @sql,N'@aa varchar(100) output',@idname output
select @idname 结果