An app is developed where a user picks what data he wants to see in a report. Having data as
ReportDataValues
ID | TableName | ColumnName |
---|---|---|
1 | customer | first_name |
2 | address | zip_code |
Customer
ID | first_name | last_name | address_id |
---|---|---|---|
1 | joe | powell | 1 |
2 | andy | smith | 2 |
Address
ID | street | zip_code |
---|---|---|
1 | main ave. | 48521 |
2 | central str. | 56851 |
is it possible using generic SQL mechanisms (PIVOT, UNPIVOT or other way) to select such data from only specified table.column pairs in DataValues table as rows so the query is compatible with SQL Server and Oracle and is not using dynamic execution of generated statements (like EXEC(query) or EXECUTE IMMEDIATE (query) ), so the result would be like
Col1 | Col2 |
---|---|
joe | 48521 |
andy | 56851 |
Later SQL statement will be used in a SAP Crystal Reports reporting engine.