i have the following store procedure
use CouponTest
go
CREATE PROCEDURE [dbo].[sp_UpdateCouponCount]
AS
Declare @couponCount int,
@CouponName nvarchar(50),
@couponIdFromQuery int
Declare curP cursor For
select COUNT(*) as totalcount ,
Name as name,
couponuse.couponid as couponid
from Coupon as coupon
join CouponUse as couponuse
on
coupon.id = couponuse.couponid
where couponuse.couponid=coupon.id
group by couponuse.couponid , coupon.Name
OPEN curP
Fetch Next From curP Into @couponCount, @CouponName,@couponIdFromQuery
While @@Fetch_Status = 0 Begin
print @couponCount
print @CouponName
update Coupon SET NofUses=@couponCount
where CouponUse.couponid=@couponIdFromQuery
Fetch Next From curP Into @couponCount, @CouponName
End -- End of Fetch
Close curP
Deallocate curP
...
Go to the complete details ...