Connecting Tech Pros Worldwide Help | Site Map

How to compare two different columns in two different rows.

  #1  
Old October 28th, 2008, 06:35 PM
Gabe
Guest
 
Posts: 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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare Two Datatables John Wright answers 7 July 3rd, 2008 09:25 PM
Why Same query results in two different # in SQL Server vs MS Access dsdevonsomer@gmail.com answers 4 February 21st, 2008 11:05 PM
Field compare report Ken Smith answers 1 November 13th, 2005 06:21 AM
REQ How would I compare multiple date fields in one table to find the latest entry Gleep answers 4 July 17th, 2005 06:37 AM