Hi
It would be something like this (your code inside the loop may need adjusting)
declare @PAID int
declare @FREE int
declare @CLASS int
Set @CLASS = 10
While @CLASS < 350
Begin
select @FREE = count(*)
from submitqueue
where cost = 0
and processstatus not in (4,5,6)
and class = @CLASS
select @PAID = count(*)
from submitqueue
where cost > 0
and processstatus not in (4,5,6)
and class = @CLASS
/* INSERT FREE AD STATS */
insert into ADCOUNTSBYCLASS (
DATE,
CLASS,
COUNT,
TYPE
)
values (
getdate(),
@CLASS,
@FREE,
'FREE'
)
/* INSERT PAID AD STATS */
insert into ADCOUNTSBYCLASS (
DATE,
CLASS,
COUNT,
TYPE
)
values (
getdate(),
@CLASS,
@PAID,
'PAID')
Set @CLASS = @CLASS+10
End
Main Topics
Browse All Topics





by: RDWaibelPosted on 2004-11-15 at 10:00:06ID: 12586083
Here you go:
declare
@PAID int,
@FREE int,
@CLASS int
While @Class <= 350 BEGIN
-- For @CLASS = 10 to 350 step 10
select @FREE = count(*)
from submitqueue
where cost = 0
and processstatus not in (4,5,6)
and class = @CLASS
select @PAID = count(*)
from submitqueue
where cost > 0
and processstatus not in (4,5,6)
and class = @CLASS
/* INSERT FREE AD STATS */
insert into ADCOUNTSBYCLASS (
DATE,
CLASS,
COUNT,
TYPE
)
values (
getdate(),
@CLASS,
@FREE,
'FREE'
)
/* INSERT PAID AD STATS */
insert into ADCOUNTSBYCLASS (
DATE,
CLASS,
COUNT,
TYPE
)
values (
getdate(),
@CLASS
@PAID,
'PAID'
)
Select @Class = @Class + 10
END
There is not a FOR...Next loop so you can use the While...Begin...End (as seen above!)
Happy DBA-ing!
=) Rob