I am having a Metadata table as below:
RULE_NAME COL_NAME COL_VAL
RULE_1 COL_1 ABC
RULE_1 COL_5 XYZ
RULE_2 COL_2 123
RULE_2 COL_3 A2d5
RULE_2 COL_8 X0IL
RULE_3 COL_1 PQR
RULE_3 COL_7 9789
I need to generate a WHERE clause using the data from this table. the WHERE clause should be like this:
WHERE
(COL_1 = 'ABC' AND COL_5 = 'XYZ') --from Rule 1 records
OR
(COL_2 = '123' AND COL_3 = 'A2D5' AND COL_8 = 'X0IL') --From Rule 2 records
OR
(COL_1 = 'PQR' AND COL_7 = '9789') --from Rule 3 records
Is this possible to do with normal SQL (I am on Teradata)? Can someone give me some pointers on how to achieve this?
Thanks.
The following returns each of the clauses on a separate line:
Is that close enough?
If you don’t have the ‘oreplace’ function, you can do something like: