declare @var varchar(10);
set @var='';
select @var='Column1,column2,column3,column4,column5';
select @var = @var + COLUMN_NAME + ','
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = ' T_TableName ' and column_name=@var
exec ('select top 10 '+@var+' from T_TableName order by '+ @var+' desc ')
set @var='';
select @var='Column1,column2,column3,column4,column5';
select @var = @var + COLUMN_NAME + ','
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = ' T_TableName ' and column_name=@var
exec ('select top 10 '+@var+' from T_TableName order by '+ @var+' desc ')
No comments:
Post a Comment