Is there any SQL
lingo to return JUST the first two columns
of a table WITHOUT knowing the field names?
S
There it´s
declare @select varchar(max)
set @select = 'select '
select @select=@select+COLUMN_NAME+','
from information_schema.columns
where table_name = 'TABLE' and ordinal_position <= 2
set @select=LEFT(@select,LEN(@select)-1)+' from TABLE'
exec(@select)
Or do I have to go the long way around and find out the column names first? How would I do that?
It's pretty easy to do manually.
Just run this first
select * from tbl where 1=0
This statement works on all major DBMS without needing any system catalogs. That gives you all the column names, then all you need to do is type the first two
select colname1, colnum2 from tbl