Hello ...
I am trying to obtain some assistance for using conditional logic with DB2.
My task is to select a record in a table based on date fields. Each record has a date field. Users add records to this table with a specific calendar date (e.g. 2007-10-21, 2007-12-31, etc...).
The basic query is:
The logic I am trying to employ needs to look at the date entered (e.g. 2007-10-21). If the date is equal to a Sunday, then include a second date in the WHERE clause. If the date is equal to Monday, then include a second date in the WHERE clause. Etc...
I've looked at the CASE statement, but am not sure how to apply this.
Thanks in advance ...
I am trying to obtain some assistance for using conditional logic with DB2.
My task is to select a record in a table based on date fields. Each record has a date field. Users add records to this table with a specific calendar date (e.g. 2007-10-21, 2007-12-31, etc...).
The basic query is:
Code:
SELECT RECORD,
DATE
FROM TABLE
WHERE DATE = '2007-10-21';
The logic I am trying to employ needs to look at the date entered (e.g. 2007-10-21). If the date is equal to a Sunday, then include a second date in the WHERE clause. If the date is equal to Monday, then include a second date in the WHERE clause. Etc...
Code:
SELECT RECORD,
DATE
FROM TABLE
WHERE DATE = '2007-10-21'
IF DAYOFWEEK(DATE) = 0 THEN ALSO SEARCH '2100-09-09'
IF DAYOFWEEK(DATE) = 1 THEN ALSO SEARCH '2100-03-03'
IF DAYOFWEEK(DATE) = 2 THEN ALSO SEARCH '2100-04-04'
IF DAYOFWEEK(DATE) = 3 THEN ALSO SEARCH '2100-05-05'
IF DAYOFWEEK(DATE) = 4 THEN ALSO SEARCH '2100-06-06'
IF DAYOFWEEK(DATE) = 5 THEN ALSO SEARCH '2100-07-07'
IF DAYOFWEEK(DATE) = 6 THEN ALSO SEARCH '2100-08-08'
IF DAYOFWEEK(DATE) = 7 THEN ALSO SEARCH '2100-10-10'
ELSE ONLY SEARCH DATE;
I've looked at the CASE statement, but am not sure how to apply this.
Thanks in advance ...