I'm not sure how to do this but I have a database that has Incidents that have an IncidentID. There are usually multiple records for an IncidentID - they are seperate events for each Incident. I was searching for the records by the timestamp date but I wouldn't get all of the events for a particular Incident if there were some events prior to that. I am calling a view from a stored procedure.
For instance:
This is what I get:
IncidentID Date & Time Incident Status
1776 10/2/3006 11:56:50 PM Resolved
1781 10/2/2006 1:27:58 PM Resolved
1783 10/2/2006 4:42:35 AM Open
1783 10/2/2006 1:22:58 PM Resolved
The problem is IncidentID # 1776 was Opened on 9/27/2006 and there are 4 events for this Incident so the list is only partial for that Incident. The same for # 1781. I want to run a Select statement to get the IncidentID's in the date range and then pass the IncidentID's to the view to get all events for those Incidents.
Something like this:
And then call this:
Can I run both of these in one stored procedure?
Thanks.
For instance:
Code:
CREATE PROCEDURE [dbo].[stoSelectIncidentLog]
@StartDate datetime,
@EndDate datetime
AS
SELECT * FROM vHDIncidentLog WHERE TimeStamp BETWEEN '10/2/2006' AND '10/2/2006'
ORDER BY IncidentID, TimeStamp
GO
This is what I get:
IncidentID Date & Time Incident Status
1776 10/2/3006 11:56:50 PM Resolved
1781 10/2/2006 1:27:58 PM Resolved
1783 10/2/2006 4:42:35 AM Open
1783 10/2/2006 1:22:58 PM Resolved
The problem is IncidentID # 1776 was Opened on 9/27/2006 and there are 4 events for this Incident so the list is only partial for that Incident. The same for # 1781. I want to run a Select statement to get the IncidentID's in the date range and then pass the IncidentID's to the view to get all events for those Incidents.
Something like this:
Code:
SELECT Distinct IncidentID As Incidents FROM HelpDeskIncidents WHERE TimeStamp BETWEEN '10/2/2006' AND '10/2/2006'
And then call this:
Code:
SELECT * FROM vHDIncidentLog
WHERE IncidentID = Incidents
ORDER BY IncidentID, TimeStamp
Can I run both of these in one stored procedure?
Thanks.