Recursive Sql Update Query

Posted by Saranpselvam under Sql Server on 9/12/2014 | Points: 10 | Views : 1321 | Status : [Member] | Replies : 3
HI

I need to update a column of a table . if that particular column has any null values then i have to update the column. this should by done one by one. so i wrote a a query which take each row one by one and update

WHILE exists(Select count(projid) From test Where sumVolume  IS NULL)
begin
update a set a.sumVolume12weeks=b.sumVolume12weeks from tatsla_t1_test a
left outer join (
SELECT top 1 CUSTID,PROJID,recvdate,dbo.sumValue(custid,projid,recvdate) as sumVolume
FROM test WHERE sumVolumeIS NULL
)b on a.custid=b.custid and a.projid=b.projid and a.recvdate=b.recvdate
where a.custid=b.custid and a.projid=b.projid and a.recvdate=b.recvdate
end





Responses

Posted by: Naveenhcl on: 9/12/2014 [Member] Starter | Points: 25

Up
0
Down
Ok, what's the issue are you facing by using above code.

Saranpselvam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/12/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Can you explain your issue by sample data and expected output ?

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Saranpselvam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetguy on: 9/12/2014 [Member] Starter | Points: 25

Up
0
Down
what the value you need to update, if the sumVolume IS NULL. You need to approach aeither while loop or you can use update tables with join. Here it is not required to use both.

Saranpselvam, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response