HI All,
After a little while out of the game i am getting back into coding in SQL, however i seem a bit rusty..
This cursor is not picking up the new @Auth code when it picks up the next @idcol of the next record in the loop
can someone help me...i am sure its something really stupid but its driving me crazy!!
Many thanks in advance for your help
**************************CODE**************************
declare @idcol int
declare @auth int
declare @maxid int
set @idcol = 1
set @maxid = (select max(iddcol) from #tempa)
declare cur CURSOR
for
--declare @idcol int
--set @idcol = 57
select iddcol,trans from #tempa where iddcol = @idcol
open cur
fetch next from cur into @IDcol,@Auth
--while @lastidcol <> @idcol
WHILE @idcol <= @maxid
BEGIN
if @auth = 1
begin
update #tempa
set
TotalAmount = sumtotal,
progressflag = 1
from #tempa a
join
( select iddcol,mksystemid,mkaccountid,sum(txnvalue) + sum(cashback) + sum(gratuity) as sumtotal
from #tempa
WHERE iddcol = @idcol
group by iddcol, mksystemid, mkaccountid
) b on a.iddcol = b.iddcol
print 'goodbye'
end
else if @auth = 0
begin
update #tempa
set
TotalAmount = 0,
progressflag = 1
from #tempa a
where iddcol = @idcol
print 'hello'
print @idcol
print @auth
end
--set @lastidcol = @idcol
set @idcol = @idcol +1
END
fetch next from cur into @IDcol,@Auth
close cur
deallocate cur
**************************CODE**************************
After a little while out of the game i am getting back into coding in SQL, however i seem a bit rusty..
This cursor is not picking up the new @Auth code when it picks up the next @idcol of the next record in the loop
can someone help me...i am sure its something really stupid but its driving me crazy!!
Many thanks in advance for your help
**************************CODE**************************
declare @idcol int
declare @auth int
declare @maxid int
set @idcol = 1
set @maxid = (select max(iddcol) from #tempa)
declare cur CURSOR
for
--declare @idcol int
--set @idcol = 57
select iddcol,trans from #tempa where iddcol = @idcol
open cur
fetch next from cur into @IDcol,@Auth
--while @lastidcol <> @idcol
WHILE @idcol <= @maxid
BEGIN
if @auth = 1
begin
update #tempa
set
TotalAmount = sumtotal,
progressflag = 1
from #tempa a
join
( select iddcol,mksystemid,mkaccountid,sum(txnvalue) + sum(cashback) + sum(gratuity) as sumtotal
from #tempa
WHERE iddcol = @idcol
group by iddcol, mksystemid, mkaccountid
) b on a.iddcol = b.iddcol
print 'goodbye'
end
else if @auth = 0
begin
update #tempa
set
TotalAmount = 0,
progressflag = 1
from #tempa a
where iddcol = @idcol
print 'hello'
print @idcol
print @auth
end
--set @lastidcol = @idcol
set @idcol = @idcol +1
END
fetch next from cur into @IDcol,@Auth
close cur
deallocate cur
**************************CODE**************************