Home » SQL & PL/SQL » SQL & PL/SQL » Updating table using column heading from another table
Updating table using column heading from another table [message #18643] Fri, 08 February 2002 05:58 Go to next message
andy
Messages: 92
Registered: December 1999
Member
Is there a way to update one table using the value in another table, but possibly using the column name from that table to link to the original table although this may not be necessary.

Example:

Table1

EQNUM N1
===== ==
1234 4
3456 6
4444 1

Table2

EQNUM ATTRIB NUMVALUE
===== ====== ========
1234 N1
3456 N1
4444 N1

The idea is to use the contents of Attrib from Table 2 to link to the column name in Table 1 with the same column heading and retrieve the value.

The column heading N1 in Table1 will always be the same as the Attrib value in Table2 if this helps in resolving the problem.

I have tried the following, but it obviously brings back multiple rows for each line:

update Table2
set numvalue = (select tab1.n1 from table1 tab1, table2 tab2 where tab1.epnum = tab2.eqnum)
where tab2.attrib = 'N1'

Any help would be much appreciated.

Thanks.
Re: Updating table using column heading from another table [message #18646 is a reply to message #18643] Fri, 08 February 2002 06:35 Go to previous messageGo to next message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
try this

update Table2
set numvalue = (select tab1.n1 from table1 tab1 where tab1.epnum = tab2.eqnum)
where tab2.attrib = 'N1'
Re: Updating table using column heading from another table [message #18679 is a reply to message #18643] Sun, 10 February 2002 23:55 Go to previous message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
hi,

i think the datatype of n1 and numvalue are different.please change your code accordingly. if u still have problem then send me table structure.

cheers
pratap
Previous Topic: ORDER BY
Next Topic: Re: deleting column from table?
Goto Forum:
  


Current Time: Fri Apr 26 10:44:38 CDT 2024