Hi,
I have a table [A] with a bunch of columns and another table with a list of those columns. Table not only lists the names of the columns but categorizes them.
I need to select from [A] where the column name exists in when the category = 'x'.
I know the layout is not ideal but a program sets up the table structures. Anybody know how I can reference the column names in the query?
I'm working with something like:
Select *
from [A]
where [A].* in
(Select field_name from where category = 'potatoes')
MS SQL 2000 How to refer to a column name in query?
Moderator: General Moderators
Re: MS SQL 2000 How to refer to a column name in query?
There are 10 types of people in this world, those who understand binary and those who don't
Re: MS SQL 2000 How to refer to a column name in query?
Thanks for the quick reply. Maybe I didn't specify my problem correctly:
TableA has a bunch (287) of columns and TableB has the names of the columns as entries (rows) along with a category for each. I want to build a (dynamic) query where I select only the columns in TableA where the name of the columns is in TableB for a given category. To clarify, TableB has a field named "field_name"
An example:
Parentheses are the names of the columns and directly below are example entries for both tables.
TableA
(question_1 , question_2 , question_3)
"NULL" | "NULL" | "NULL"
TableB
(field_name , category)
"question_1" | "apples"
"question_2" | "monkeys"
"question_3" | "sauerkraut"
In this case, I want to (pseudocode):
SELECT * FROM TableA WHERE TableA.* IN
(select field_name from TableB where category = 'apples')
I'm going to use the front end to manage this but I'd like to know if this is actually possible. Thanks for your help
TableA has a bunch (287) of columns and TableB has the names of the columns as entries (rows) along with a category for each. I want to build a (dynamic) query where I select only the columns in TableA where the name of the columns is in TableB for a given category. To clarify, TableB has a field named "field_name"
An example:
Parentheses are the names of the columns and directly below are example entries for both tables.
TableA
(question_1 , question_2 , question_3)
"NULL" | "NULL" | "NULL"
TableB
(field_name , category)
"question_1" | "apples"
"question_2" | "monkeys"
"question_3" | "sauerkraut"
In this case, I want to (pseudocode):
SELECT * FROM TableA WHERE TableA.* IN
(select field_name from TableB where category = 'apples')
I'm going to use the front end to manage this but I'd like to know if this is actually possible. Thanks for your help
Re: MS SQL 2000 How to refer to a column name in query?
It's a weird DB design
Try to redesign.
There are 10 types of people in this world, those who understand binary and those who don't