Скрипт для команды SelectTopNRows из SSMS
drop table #yourtable;
create table #yourtable(id int, location varchar(25));
insert into #yourtable values
('1','Singapore'),
('2','Vancouver'),
('3','Egypt'),
('4','Tibet'),
('5','Crete'),
('6','Monaco');
drop table #temp;
create table #temp( col1 int );
Declare @Script as Varchar(8000);
Declare @Script_prepare as Varchar(8000);
Set @Script_prepare = 'Alter table #temp Add [?] varchar(100);'
Set @Script = ''
Select
@Script = @Script + Replace(@Script_prepare, '?', [location])
From
#yourtable
Where
[id] is not null
Exec (@Script);
ALTER TABLE #temp DROP COLUMN col1 ;
select * from #temp;