Subject | dynamic column alias |
---|---|
Author | crizoo4712 |
Post date | 2007-06-20T08:13:51Z |
Hello all,
I have two tables. One of them contains headers (head_1, head_2, ...)
which contain field names like "STREET", "ZIP CODE", ...
In other cases this could be "PHONE NUMBER" for head_1, "MAIL
ADDRESS" for head_2 and so on..
In another table the values are stored in varchar-fields (data_1,
data_2, ...) They could be "CHURN CREEK RD." for data_1, "471109" for
data_2, or "001 6767 689903" for data_1, "noone@..." for
data_2 and so on.
In a select I want to name the output-columns with aliases depending
on the values stored in the headers and depending on a component_id
which determines the stored object (address-data or contact-data..).
In other words, I want to do something like the following:
"select data_1 as (select header_1 from table_1 where..)
from table_2 where component_id = ..."
I know, that this is not possible in sql, but does someone's got an
idea for a workaround?
regards, Christoph
I have two tables. One of them contains headers (head_1, head_2, ...)
which contain field names like "STREET", "ZIP CODE", ...
In other cases this could be "PHONE NUMBER" for head_1, "MAIL
ADDRESS" for head_2 and so on..
In another table the values are stored in varchar-fields (data_1,
data_2, ...) They could be "CHURN CREEK RD." for data_1, "471109" for
data_2, or "001 6767 689903" for data_1, "noone@..." for
data_2 and so on.
In a select I want to name the output-columns with aliases depending
on the values stored in the headers and depending on a component_id
which determines the stored object (address-data or contact-data..).
In other words, I want to do something like the following:
"select data_1 as (select header_1 from table_1 where..)
from table_2 where component_id = ..."
I know, that this is not possible in sql, but does someone's got an
idea for a workaround?
regards, Christoph