Hi I have a little problem. I must exec query in that style. In the example, something like that
declare @name varchar(max)
set @name = 'ColumnID'
select @name from Account
that return a lot of 'ColumnID' but I will have a result column ColumnID in Account table
You'll be wanting to execute a dynamic SQL Statement:
exec('select ' + @name + ' from Account');
Be wary of over-liberal use of these, as they can come with pretty hefty baggage:
Advantages
Disadvantages
Try this:
declare @name varchar(max);
set @name = 'ColumnID';
exec('select ' + @name + ' from Account');
try using sp_executesql stored procedure
declare @name nvarchar(20);
set @name = 'ColumnID';
declare @sql nvarchar(max)
set @sql='select ' + @name + ' from Account'
exec sp_executesql @sql
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.