0

I need to pull values from one table that are only 24 hours from the date in another table in sybase ase 15.5.

Here is my wrong code:

SELECT p_generaldata.admissiontime,*
 FROM   Patient.dbo.P_MonVals P_MonVals 
               INNER JOIN Patient.dbo.P_GeneralData P_GeneralData 
               ON P_MonVals.PatientID=P_GeneralData.PatientID
where  p_generaldata.admissiontime < P_MonVals.entertime +1
order by p_generaldata.patientid ASC

Im trying to return all rows in p_monvals, where the entertime in that table is less than 24 hours after the admissiontime.

the error im getting is INT is not compatible with DATETIME

Any help greatly appreciated

thank you

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
bry
  • 3
  • 1

3 Answers3

0

Use function dateadd to sum 1 day in your date time:

dateadd(dd, 1, P_MonVals.entertime)

Reference: Sybase dateadd function.

Caffé
  • 1,161
  • 1
  • 9
  • 19
0

Take a look a the DateAdd function, and add a day to the entertime

Example from docs:

Adds one day to a date:

declare @a date
select @a = "apr 12, 9999"
select dateadd(dd, 1, @a)

In your case...

...
where  p_generaldata.admissiontime < dateadd(dd, 1, P_MonVals.entertime)
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
  • I added your line but it still returned rows from monvals that were three days after the admission date. what im after is admission time of say 14/04/2014 20:00:00, it will return rows from monvals with an entertime between 14/04/2014 20:00:00 and 15/04/2014 20:00:00 , so its not all results from the next day, its 24 hours from the admission time. thanks so much – bry Sep 16 '14 at 15:14
  • Can't you use `dateadd`, using hours instead of days in that case? – Christian Phillips Sep 16 '14 at 15:25
  • thanks mate. the solution was in dateadd....where P_MonVals.entertime between p_generaldata.admissiontime and dateadd(hh, 24, p_generaldata.admissiontime).... thank you – bry Sep 16 '14 at 15:44
0

You want to use the dateadd function:

SELECT p_generaldata.admissiontime, *
FROM Patient.dbo.P_MonVals P_MonVals 
INNER JOIN Patient.dbo.P_GeneralData P_GeneralData 
ON P_MonVals.PatientID=P_GeneralData.PatientID
WHERE p_generaldata.admissiontime < DATEADD(dd, 1, P_MonVals.entertime)
ORDER BY p_generaldata.patientid ASC
jpw
  • 44,361
  • 6
  • 66
  • 86