I am trying to write a query that uses if... then... else (DECODE), but I'm having trouble getting it to work.
Here is my current query -
Sometimes the sub query returns empty if this happens I want to use an alternative date. The theory is something like this -Code:SELECT t.Start_Dat, t.End_Dat
FROM Tariff t
WHERE t.Start_Dat >= (SELECT max(t.start_dat)
FROM Tariff t
WHERE t.Start_dat <= to_date('21/11/2003', 'dd/mm/yyyy'))
Here is my query so far but I can't get it to workCode:SELECT t.Start_Dat, t.End_Dat
FROM Tariff t
WHERE t.Start_Dat >= (If select max = '' Then '20/11/2003')
It doesn't seem to like the select max within the decode? Does anyone know how to make this work?Code:SELECT t.Start_Dat, t.End_Dat
FROM Tariff t
WHERE t.Start_Dat >= (DECODE(SELECT Max(t.start_dat)
FROM Tariff t
WHERE t.Start_Dat <= to_date('21/11/2003', 'dd/mm/yyyy'), '', to_date('20/11/2003', 'dd/mm/yyyy')))
Any help will be greatly appreciated
Cheers Al
