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

How to compare two different columns in two different rows.

P: n/a
I'm completely new to SQL and this puzzle is over my head. Any advice
would be greatly appreciated.

Table: Visits
Columns:
RecNo VisitNo EnterDate
LeaveDate
M1111232 V11112869 2008-09-23 10:25:00.000 2008-09-23 10:31:00.000
M1111232 V11112943 2008-10-24 15:56:00.000 NULL
M1111233 V11112877 2008-09-23 15:53:00.000 NULL

I have a table as described above. It contains several thousand rows
ordered by RecNo by VisitNo.

VisitNo is the key.

If there is only one row for a RecNo, I want to bypass it.

If there is more than one row per RecNo AND
If the row immediately below the current row has the same RecNo as the
first row
I want to compare the Leave Date of the 1st row with the Enter Date of
the 2nd row and calculate the diff. in # of days.

If the number of days is greater than 3, I want to list the two date
values from above and the RecNo. in one row.

How do I do this?

Please help. I am completely befuddled. Thanks, Gabe
Oct 28 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.