468,117 Members | 1,536 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to compare two different columns in two different rows.

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
0 1830

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Prakash RudraRaju | last post: by
2 posts views Thread by gibster | last post: by
4 posts views Thread by Justin Emlay | last post: by
7 posts views Thread by John Wright | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.