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.
| Author |
Topic |
|
ofsouto
Starting Member
22 Posts |
Posted - 2005-01-31 : 06:27:03
|
| Hi, dearIs 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.ObedeBrazil |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-31 : 07:59:11
|
use *select * from MyTableGo with the flow & have fun! Else fight the flow |
 |
|
|
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. |
 |
|
|
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_namefrom information_schema.columnswhere table_name = 'YourTableName' and ordinal_position = 2 -- ordinal_position is the column indexset @sql = 'select ' + @columnName + ' into ##temp from YourTableName'exec(@sql)select * from ##temp Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|