Generating dynamic queries

Database
Enthusiast

Generating dynamic queries

Hi,

We have a requirement where we need to extract some (common) fields from a table for different dates based on regions.
For eg : If it is US, then we need to get data for (say 1st Jan,2010) . If JPN then (2nd Jan,2010) and if UK then (3rd Jan,2010).

I do not want to fire this query thrice so what i wanted was based on region , if we can load the data for 3 dates dynamically.
So ultimately in my table I should have data for these 3 dates-region combination which means if I query the table for 2nd Jan I should get data only for JPN.

Please let me know if dynamic query generation is possible . If yes then how.

TIA..
1 REPLY
Junior Supporter

Re: Generating dynamic queries

SELECT *
FROM THE_TABLE
WHERE THE_DATE = your_date
AND THE_COUNTRY = CASE THE_DATE
WHEN '2010-01-01' THEN 'US'
WHEN '2010-01-02' THEN 'JPN'
WHEN '2010-01-03' THEN 'UK'
END;

HTH.

Cheers.

Carlos.