Hi,
I'm trying to create particular view to help me with some reporting. My main table looks like this:
ID, DateUpdated, Status.
Status can have a value of 1, 2, 3 or 4.
I want to create a view that will show me what the state of the database was on each date. It should look like this:
Date, Status1, Status2, Status3, Status4
Where each of the status columns are the count of records with that status, and that have an UpdatedDate less than or equal to the Date field.
The query I have so far looks like this:
declare @update as datetime
declare date_cursor insensitive cursor for
select dbo.vwDates.dates from dbo.vwDates
open date_cursor
fetch next from date_cursor into @update
while (@@fetch_status <> -1)
begin
select count(*) from dbo.tblDts where Status = 1 and UpdateDate < @update
end
close date_cursor
deallocate date_cursor
I'm not sure if using a cursor is the correct thing to do, but it's all I could think of. All my resources get eaten up when I run the query in query analyser, and nothing gets displayed.
Any help on how to do this is much appreciated.
Thank you,
Phin
I'm trying to create particular view to help me with some reporting. My main table looks like this:
ID, DateUpdated, Status.
Status can have a value of 1, 2, 3 or 4.
I want to create a view that will show me what the state of the database was on each date. It should look like this:
Date, Status1, Status2, Status3, Status4
Where each of the status columns are the count of records with that status, and that have an UpdatedDate less than or equal to the Date field.
The query I have so far looks like this:
declare @update as datetime
declare date_cursor insensitive cursor for
select dbo.vwDates.dates from dbo.vwDates
open date_cursor
fetch next from date_cursor into @update
while (@@fetch_status <> -1)
begin
select count(*) from dbo.tblDts where Status = 1 and UpdateDate < @update
end
close date_cursor
deallocate date_cursor
I'm not sure if using a cursor is the correct thing to do, but it's all I could think of. All my resources get eaten up when I run the query in query analyser, and nothing gets displayed.
Any help on how to do this is much appreciated.
Thank you,
Phin