Compare column name in one table to a column value in another

Compare column name in one table to a column value in another

Post by John Smit » Sat, 09 Feb 2002 00:25:58

I have:

    Table1 t1
      Firstname,  [varchar]
      Lastname,  [varchar]
      Issueno, [int]
      col1,  [varchar]
      col2,   [varchar]
      col3   [varchar]......col400   [varchar]

    Table2 t2
      Indexno,   [varchar]  (The values in Indexno are: 'col1', 'col2',
'col3'.....and so on)
      Issueno  [int]

I want to write a query to join both tables and produce Firstname,
Lastname and issueno where col1 = '1' and compare the column name in
Table1 with the value of column Indexno in Table2.

How can I do this?


Compare column name in one table to a column value in another

Post by Joe Celk » Sat, 09 Feb 2002 00:45:15

1) You have been here before; read the note at the bottom of this
posting.  There are no keys, and all columns are NULL-able and the way
you declared them, they will default ot VARCHAR(1), which is useless.
In fact, this thing is not a table!!  And there is no sample data.  

2) PLease, please, please read a book on database design.  I remember
your last post and you still don't know what a Normal Form is.  

 Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!


1. When comparing a field name with a column name of more than one word

Do I need a special syntax for a comparison such as

WHERE PromoterName = ThisPromoterName

When ThisPromoterName is both a first and last name ?
i.e. ThisPromoterName = bob smith
All exmples in my books have a single word in the comparison.
I can see that joining them with an undescore would work,
but isn't there another way ? Actually I could swear it was
alread working and that maybe I am entirley misguided
by making a different mistake which is now effecting this part
of the statement.


2. Stored Procedure problem

3. Copy Datetime Values from one Column to another before 2nd Columns values

4. remote access problems V7.30 -> V7.13

5. inserting multible columns from one table into a single column in another table

6. any Java databases without royalty payments?

7. Splitting values from one column into two new columns

8. 'dt:enumeration' type in the XML-persisted recordset

9. Transforming one column based on value in another column

10. column name in @Variable, column value of @Varialble

11. Faster way to compare column values between tables?

12. Script to copy data from one existing column to a new column in another existing table

13. Updating a row column of a table using values from another row column