Question : SQL Select by Date

I have a table with two columns;  discount_rate, and effective date. The table has both historic and future entries.

Discount_rate       Effective_Date
8.5                         7/1/2003
7.0                         1/1/2008
12                          7/1/2010
9                            10/1/2010

Using by invoice_date I need to select and return the proper discount rate. The effective_date must be <= the Invoice_date.

I am quering a DB2 database

Answer : SQL Select by Date

Sorry, left out order by.  You need to provide a invoice date to it, I assume the invoice record hasn't actually been created when this query is being used?

select Discount_Rate from MyTable
where Effective_Date <= <Invoice_date>
Order by Effective_Date DESC
FETCH FIRST 1 ROW ONLY
Random Solutions  
 
programming4us programming4us