468,103 Members | 1,300 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Need help urgently, have to compare dates between 2 rows in one table

2
Have to compare dates of two rows in one table
Input table
COL1| COL2| COL3| COL4
1| A| 1-Jan-07| 6-Feb-08
2| A| 7-Feb-08| 31-Mar-08
3| A| 1-Jan-09| NULL

SQL code to compare COL 4 date (Row 1) with COL 3 date (row 2)
and compare COL 4 date (Row 2) with COL 3 date (row 3)

If COL2 (ROW2) date is equal to COL 3 (ROW 1) + 1 = output Col 4 =A
If COL2 (ROW2) date is equal to COL 3 (ROW 1) + 2 = output Col 4 =R


OUTPUT table
COL1| COL2| COL3| COL4
A| 1-Jan-07|| 6-Feb-08| A
A| 7-Feb-08| 31-Mar-08| O
A| 1-Jan-09| NULL| R
Jul 30 '09 #1
2 3472
ck9663
2,878 Expert 2GB
Here, tweak this...

Good luck!

--- CK
Jul 30 '09 #2
site
2
@site
Correction in Below query-Updated query
Jul 30 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Richard Hollenbeck | last post: by
11 posts views Thread by Geoff Jones | last post: by
3 posts views Thread by Danielle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.