Okay, I appreciate your help in trying to provide a better way to do this but these are pretty simple SQL statements. My problem however, is not as simple. It is not possible to join my temp table to my date range table. Also, as I stated before, there may be 1 or more date ranges to filter out so I can't very well run a nested select that pulls out 3 (possible) date ranges to evaluate. Here are some sample records:
Let's say I am dealing with employee "123456"
My temp table holds these records (they are specific to the EmployeeID passed to the stored procedure - ID not stored in temp table)
ReportDate JobCode Pay
09/29/2003 Job 1 5.87
09/29/2003 Job 2 6.00
09/30/2003 Job 3 4.54
10/01/2003 Job 4 7.34
10/02/2003 Job 5 2.15
10/03/2003 Job 6 8.17
10/04/2003 Job 7 8.00
My date range table holds these records
EmployeeID FirstDay LastDay Reason
001212 09/25/2003 10/01/2003 Blah
003434 09/28/2003 10/02/2003 Blah
123456 09/28/2003 09/30/2003 Blah
123456 10/03/2003 10/05/2003 Blah
So there are my two tables. Now, I call my stored procedure which takes a day in the week and employee ID as inputs.
Let's say:
exec proTest '9/30/2003 4:30 PM', '123456'
The first thing my procedure does is calculate the start and end dates of the week. In this case:
Begin date: 9/28/2003 12:00:00 AM
End date: 10/4/2003 11:59:59 PM
Next, I do some calculations to create the records which will go into my temp table.
Now I have both tables ready to go. I need to delete from my temp table those records where the ReportDate falls between any relevant date ranges stored in my date range table. Going on the records I've provided, I have two such relevant ranges:
9/28/2003 - 9/30/2003
10/3/2003 - 10/5/2003
I need to compare these date ranges with what is in my temp table. The ultimate result will leave the following records in my temp table:
ReportDate JobCode Pay
10/01/2003 Job 4 7.34
10/02/2003 Job 5 2.15
The best way I could think to do this is with a cursor. The cursor works and when I run the procedure in Query Analyzer I get the desired results (in the second recordset). But the first recordset the SP returns is that of the cursor. I don't want my cursor select statement to return a result set to the calling application. Is there a way to do this similar to
SET NOCOUNT ON?
Thanks for reading,
LampknLn45
LampknLn45