I have a daycode
column that stores values like 1,2...7
then in a different table I have cols like field1,field2...field7
I can join them on a key
, but how do I select the specific fieldX
column based on values passed?
Table 1 has the following columns
-------------
id
prodno
field1
field2
field3
field4
field5
field6
field7
Where each fieldX represents a value for monday, tuesday and so on till sunday.
Table 2 has the following columns
-------------
id
prodno
dt
daycode
Update
t2 has columns like field1, field2 ... field7, and daycode values is 1,2 ... 7. We need to concat "field" with the value taken from daycode column.
select table1.id,select [concat('field',table2.daycode)] from table1 join
table2 on table1.id=table2.key