Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test the two records happened at the same time

Status
Not open for further replies.

lrq

Programmer
Aug 6, 2004
1
US
I have to write a SQL to find records happened at the same time.

For example, I have a table link this
PatientID
Treatment
BeginDate
EndDate

How to write a SQL to find all the patients that have
two or more treatment at the same time. For example the
following two records are considered the valid records:
101 Detox 01/01/2004 02/15/2004
101 OutPt 01/15/2004 03/31/2004

Thanks for the help!
 
Something like this ?
SELECT A.*, B.*
FROM tblPatient A INNER JOIN tblPatient B ON A.PatientID=B.PatientID
WHERE A.BeginDate<=B.EndDate AND A.EndDate>=B.BeginDate

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top