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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-10-25 : 08:51:32
|
| Billy writes "I need to make a select from a table, but I don't know the column names, I've used COL_NAME(OBJECT_ID('tablename'), 7) but it returns the name of the columnHow can I use that name now to get the data from the column?if I doselect COL_NAME(OBJECT_ID('tablename'), 7) from tablenameI can't get the data. Is ther a way to do it?Billy" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-10-25 : 09:12:11
|
| declare @sql varchar(2000)select @sql = 'select ' + COL_NAME(OBJECT_ID('tablename'), 7) + ' from tablename'from tablenameexec (@sql)yuk.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2004-10-29 : 15:25:34
|
| I agree with Nigel when he says yuk. It just confounds me that there is any reasonable (well-designed) reason why you would not know the column name. This idea of dynamic everything is rapidly becoming a pet-peeve of mine.-----------------------------------------------------Words of Wisdom from AjarnMark, owner of Infoneering |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-10-29 : 15:29:21
|
quote: Originally posted by AjarnMark This idea of dynamic everything is rapidly becoming a pet-peeve of mine.
Just now?I mean it's great when you want to gen code, and do admin stuff...But not for apps....Brett8-) |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2004-10-29 : 16:34:16
|
quote: Originally posted by X002548 Just now?
No, actually it's been a peeve of mine since shortly after I started answering questions here on SQLTeam. It just happened to spill out now. And yes, I will be blogging on this soon, too, so everyone can enjoy!-----------------------------------------------------Words of Wisdom from AjarnMark, owner of Infoneering |
 |
|
|
Knarf180
Starting Member
42 Posts |
Posted - 2004-10-29 : 16:38:18
|
| I personally love dynamic stuff. I write web based applications so everything is pretty much handled blindly. But in this case I have to agree with everyone else. Table and field names should not be dynamic. Heck, how about you make your variables dynamic too, should make everything a lot more interesting when you try to pull from them. - Frank |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-10-29 : 16:44:34
|
| You must be a mind reader:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41556I think it's gotten to the point where developers are just too lazy or incompetent to actually spend a few minutes learning about the data sources they're trying to access. Like it should be automatic and simple so they don't have to think about it. |
 |
|
|
|
|
|
|
|