Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2006, 07:37 AM
Authorized User
 
Join Date: Oct 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.


 
Old November 27th, 2006, 08:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

IMO, you should use a CASE Statement and put appropriate values for the 4th column. Since it is from two different tables, you should do the same for both the tables and do a UNION of results.

Hope that explains.
Cheers.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Media Play Apocolypse2005 Pro VB 6 7 August 9th, 2007 04:05 PM
Play Audio sumith ASP.NET 1.0 and 1.1 Basics 1 February 23rd, 2007 09:03 AM
play audio sumith ASP.NET 1.0 and 1.1 Professional 0 February 23rd, 2007 01:19 AM
SQL Programming - Play around with date wkm1925 MySQL 3 December 14th, 2006 07:15 AM
How to play music cbpanchal VB How-To 3 December 30th, 2003 04:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.