View Single Post
  #1 (permalink)  
Old November 25th, 2006, 08:37 PM
wkm1925 wkm1925 is offline
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Programming - Play around with date

Hi,

Let say, i've these following table:-

licenses
TransID | VehicleID | DateApproved
----------------------------------------
1 | AU2985 | 2004-10-13
2 | BX3290 | 2005-09-28
3 | UJ5345 | 2006-10-13
* The above VehicleID is unique.



licenses_renew
TransID | VehicleID | RenewDate
----------------------------------------
1 | AU2985 | 2005-10-18
2 | BX3290 | 2006-09-29
3 | AU2985 | 2006-10-19

DateApproved will expires after 1 year. RenewDate also will expires after 1 year.

Assume, current system date is 2005-11-26. The expected result shown these following:-
VehicleID | DateApproved_RenewDate | ExpiredDate | Status
----------------------------------------------------------------------
AU2985 | 2004-10-13 | 2005-10-13 | Need to renew
AU2985 | 2005-10-18 | 2006-10-18 | Need to renew
AU2985 | 2006-10-19 | 2007-10-19 | Still Valid
BX3290 | 2005-09-28 | 2006-09-28 | Need to renew
BX3290 | 2006-09-29 | 2007-10-29 | Still Valid
UJ5345 | 2006-10-13 | 2007-10-13 | Still Valid

How to query that?
Please help me.

Reply With Quote