By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

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

P: 2
Have to compare dates of two rows in one table
Input table
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
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
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,878
Here, tweak this...

Good luck!

--- CK
Jul 30 '09 #2

P: 2
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.