I have the following query that I use as a Stored Procedure:SELECT FirstListing,OnCallStart,OnCallEndFROM(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,'Added' as ActivityFROM mdr.dbo.mOnCallAdd WHERE DATEADD(MINUTE, mOnCalladd.StartOnCallTime, DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899')) < GETDATE() AND DATEADD(MINUTE, mOnCalladd.duration, DATEADD(MINUTE, mOnCalladd.StartOnCallTime, DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899'))) > GETDATE() and mOnCallAdd.SchedName = 'capital neph' 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,'Deleted' as ActivityFROM mdr.dbo.mOnCallDelete WHERE DATEADD(MINUTE, mOnCallDelete.StartOnCallTime, DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')) < GETDATE() AND DATEADD(MINUTE, mOnCallDelete.duration, DATEADD(MINUTE, mOnCallDelete.StartOnCallTime, DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899'))) > GETDATE() and mOnCallDelete.SchedName ='capital neph')tGROUP BY FirstListing,OnCallStart,OnCallEndHAVING SUM(CASE WHEN Activity='Added' THEN 1 ELSE 0 END) >0AND SUM(CASE WHEN Activity='Deleted' THEN 1 ELSE 0 END) =0
and while it does pull data, I'm noticing that it's not pulling it all. Here is the dataset I get when I used this query:HEART HOSP - MOORE 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000NAMC - LYSON 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000SAMC, WESTLAKE, SETON SW - SIMPSON 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000RRMC/SUMMIT/RELIANT/GT-LYSON 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000SETON & CORNERST MAIN- MOORE 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000SETON HAYS-KYLE - PEREZ 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000ST DAVIDS - ROSEN 2011-09-01 13:00:00.000 2011-09-01 18:00:00.000
and when I run a query this query:SELECT moncallAdd.FirstListing, (Dateadd(MINUTE, moncalladd.addtime, DateAdd(Day,moncalladd.adddate,'12/31/1899'))) as AddStart, 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,'Added' as ActivityFROM mdr.dbo.mOnCallAdd WHERE DATEADD(MINUTE, mOnCalladd.StartOnCallTime, DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899')) < GETDATE() AND DATEADD(MINUTE, mOnCalladd.duration, DATEADD(MINUTE, mOnCalladd.StartOnCallTime, DATEADD(DAY, mOnCalladd.StartOnCallDate, '12/31/1899'))) > GETDATE() and mOnCallAdd.SchedName = 'capital neph' UNION SELECT moncallDelete.FirstListing,(Dateadd(MINUTE, moncalldelete.addtime, DateAdd(Day,moncalldelete.adddate,'12/31/1899'))) as AddStart, 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,'Deleted' as ActivityFROM mdr.dbo.mOnCallDelete WHERE DATEADD(MINUTE, mOnCallDelete.StartOnCallTime, DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899')) < GETDATE() AND DATEADD(MINUTE, mOnCallDelete.duration, DATEADD(MINUTE, mOnCallDelete.StartOnCallTime, DATEADD(DAY, mOnCallDelete.StartOnCallDate, '12/31/1899'))) > GETDATE() and mOnCallDelete.SchedName ='capital neph'
and remove the duplicates and the deletes from my table, I am left with this dataset:BRACK & HEALTH S. - ROSEN 2011-07-22 10:22:00.000 2011-09-01 13:00:00.000 2011-09-01 18:00:00.000 AddedCALL THERESA AT 320-0963 BEFORE CHANGING 2011-07-22 10:01:00.000 2011-09-01 08:00:00.000 2011-09-01 17:00:00.000 AddedHEART HOSP - MOORE 2011-07-19 11:26:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedRRMC/SUMMIT/RELIANT/GT-LYSON 2011-07-22 10:25:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedSETON HAYS-KYLE - PEREZ 2011-07-19 11:38:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedNAMC - LYSON 2011-09-01 07:48:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedSAMC, WESTLAKE, SETON SW - SIMPSON 2011-07-22 10:26:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedSETON & CORNERST MAIN- MOORE 2011-07-19 09:46:00.000 2011-09-01 07:00:00.000 2011-09-01 18:00:00.000 AddedST DAVIDS - ROSEN 2011-07-22 10:24:00.000 2011-09-01 13:00:00.000 2011-09-01 18:00:00.000 Added
you can see that the first 2 entries on my second dataset were missed by my query, and I don't know why. Can anyone offer me a reason as to why these two entries may have been missed?Thank youDoug