Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Identifying collumns

Author  Topic 

ofsouto
Starting Member

22 Posts

Posted - 2005-01-31 : 06:27:03
Hi, dear

Is there another way to identify table collums excetpt their names?

I need to prepare a query to list table registers but I don't know the collumns name. Is it possible? Are there indexes?

I know the quantity of collumns.

Thank you very much.

Obede
Brazil

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-31 : 07:59:11
use *
select * from MyTable

Go with the flow & have fun! Else fight the flow
Go to Top of Page

ofsouto
Starting Member

22 Posts

Posted - 2005-01-31 : 08:17:57
I need to set a value of one collum to a variable.

select @var_1 = collum_1 from table_1.

I don't know the collum_1 name but I know its position.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-31 : 08:31:16
well, this will give you the column names so you can work with that:
i don't think there's a direct way to do this in sql server the way you want it...
you could put the result in dataset and do it there in the way you want it.
you could do something like:

declare @sql varchar(4000)
declare @columnName varchar(100)

select @columnName = column_name
from information_schema.columns
where table_name = 'YourTableName' and ordinal_position = 2 -- ordinal_position is the column index

set @sql = 'select ' + @columnName + ' into ##temp from YourTableName'
exec(@sql)
select * from ##temp


Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -