Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table Test(
- Col1 int,
- Col2 nvarchar(10)
- )
- select Col2 from Test
- select "2" from Test -- for illustration purposes only
- declare @col1 as varchar(128)
- declare @col2 as varchar(128)
- declare @sq1 as varchar(8000)
- select @col1 = column_name from information_schema.columns where table_name = 'tablename'
- and ordinal_position = @position
- select @col2 = column_name from information_schema.columns where table_name = 'tablename'
- and ordinal_position = @position2
- set @sql = 'select ' + col1 ',' + col2 'from tablename'
- exec(@sql)
- select table_name, column_name, ordinal_position, data_type
- from information_schema.columns
- order by 1,3
- select * from information_schema.columns
- declare @tmp table(field1 sql_variant, field2 int, field3 sql_variant)
- insert into @tmp
- select * from Test
- select field2 from @tmp
Add Comment
Please, Sign In to add comment