jeudi 21 juillet 2016

Cursor not runing thru whole table

Okay, i got this cursor and it needs to update column test with the result from @sql query. but it doesnt update each column with their own result from query, like he doesnt execute that query for each column, if u undestand me.

    declare @promenjiva nvarchar(max)
    declare @docidgodina nvarchar(max)
    declare @sql nvarchar(max)
    declare @var nvarchar(max)

    declare c1 cursor for

    select documentid,a4 from damdocumenttype1

    begin
    open c1;

    fetch next from c1 into @var,@promenjiva
    while @@fetch_status = 0
    begin
    set @promenjiva=REPLACE(@promenjiva,'C','')
    SET @SQL = --some sql query that uses @promenjiva and give the result like '3/2014, 4/2014, 5/2014, 8/2014, 16/2014, 308/2015
3/2014, 4/2014, 5/2014, 8/2014, 16/2014, 308/2015'--
    update someTable set test=@sql

    fetch next from c1 into @var,@promenjiva

    end

    end
    close c1
    deallocate c1

I can join someTable with damdocumenttype1 on documentid, just so you know

Aucun commentaire:

Enregistrer un commentaire