I have the following SP:
SELECT
moncallAdd.FirstListing,
DATEADD(MINUTE, mOnCallAdd.StartOnCallTime,
DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899')) AS OnCallStart,
DATEADD(MINUTE, mOnCallAdd.duration,
DATEADD(MINUTE, mOnCallAdd.StartOnCallTime,
DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899'))) AS OnCallEnd
FROM
mdr.dbo.mOnCallAdd
where DATEADD(DAY, mOnCallAdd.StartOnCallDate, '12/31/1899')= DATEADD(ms , 0 - DATEPART(ms , GETDATE()) ,
DATEADD(s , 0 - DATEPART(s , GETDATE()) , GETDATE())) and
mOnCallAdd.SchedName = 'arc im'
UNION
SELECT
moncallDelete.FirstListing,
DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')) AS OnCallStart,
DATEADD(MINUTE, mOnCallDelete.duration,
DATEADD(MINUTE, mOnCallDelete.StartOnCallTime,
DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899'))) AS OnCallEnd
FROM
mdr.dbo.mOnCallDelete
where DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')= DATEADD(ms , 0 - DATEPART(ms , GETDATE()) ,
DATEADD(s , 0 - DATEPART(s , GETDATE()) , GETDATE())) and
mOnCallDelete.SchedName = 'arc im'
and what I'm trying to do is as follows:
If I have a schedule that runs from 9 a.m. today to 5 p.m. today, and I run my SP anytime during that time frame, I'd like to see that schedule as part of my dataset. I can make this work for date alone, but can't figure out the time portion. Can anyone offer any assistance on this?
Addendum (was an answer, merging in -- jcolebrand)
Richard,
First let me thank you for your insight about the design of this table, and I will agree with you that it was poorly designed, but I didn't design it (thank god.) Secondly, I tried your query and I am getting better results, but it's still not eliminating all of the data that shouldn't be returned yet. Here's two results from my dataset that should have not shown up:
HEART HOSPITAL - xxxxx 2011-08-15 19:00:00.000 2011-08-16 07:00:00.000
HEART HOSPITAL - xxxxx 2011-08-15 13:00:00.000 2011-08-15 19:00:00.000
(the query was run at 9:18 CST so these wouldn't have occurred yet.)
When I run this query:
SELECT DATEADD(DAY,38490,'12/31/1899'), CAST(CONVERT(VARCHAR(10), getdate(), 111) AS DATETIME)
(38490 is the int in my first value of the StartOncallDate field)
it returns a value of:
2005-05-19 00:00:00.000 2011-08-15 00:00:00.000
Also here are a couple of lines of data in my table:
Rec Id Timestamp SchedName StartOnCallDate StartOncallTime FirstListing Duration AddDate AddTime
70550 55426893 BITTAR&ESKEW 38490 1020 YIUM 840 38490 1293
70551 55427287 ZZOB02 38494 1020 CARTER, KIMBERLY 900 38491 247