Possible Duplicate:
SQL Server Database query help
Hi,
I have a problem that I didn’t manage to solve for a very long time, and I quite desperate.
I have a Database (SQL Server) with table named ‘ProcessData’ and columns named ‘Process_Name’ (Data Type: nvarchar(50)), ‘Start_At’ (DataType: DateTime) and ‘End_At’ (Data Type: DateTime).
I need to know for each ‘Time-Interval’ (let’s say 1 minute) how many processes (Process_Name = PN) was open (after or equal to the ‘Start_at’ column and before or equal to the ‘End_At’ column) during this time (It can be a few rows with the same data).
Does anyone know how to make this query without a ‘for’ loop? (It ITSELF will promote the time), (The answer will be a table with two columns (1. The time the check took place. 2. the number of open processes at this time.) and a row for each ‘Time-Interval’ (1 minute in this example)
(If it help, I’m working with C# .net)
Many thanks,
The following should return the check time and numer of processes from the table where the start time is smaller or equal to the requested point of time and the end time is greater or equal:
This assumes you’re using SQL Server – but there may be some equivalent in other dialects.
You can extend this for time intervals also, but doing two checks, one for “start point of time” and one for “end point of time”.