Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
i want to perform this 'for loop' in stored procedure

for (int i=0;i<4;i++)
update table
Posted
Updated 1-Apr-11 1:23am
v2

SQL
DECLARE @Iterator INT
SET @Iterator = 0

WHILE (@Iterator < 4)
BEGIN
    UPDATE 
        SomeTable
    SET
        SomeField = @Iterator
    WHERE
        AnotherField = SomeCritiria

    Set @Iterator = @Iterator + 1
END 
 
Share this answer
 
v2
Comments
shms_rony 1-Apr-11 7:18am    
i have error

"must declare scalar variable @Iterator"
Dylan Morley 1-Apr-11 7:27am    
My declare was wrong way round, see updated solution
shms_rony 1-Apr-11 7:28am    
thank you
Member 10557224 17-Feb-14 8:19am    
thanks...
Hope this[^] might help you.
 
Share this answer
 
Comments
shms_rony 1-Apr-11 6:41am    
i want to perform the statement using syntax of sql server 2005
Henry Minute 1-Apr-11 7:10am    
The link given to you WAS in SQL.

Stop down-voting people that are trying to help you, or you will find that no-one will try.
 
Share this answer
 
Comments
shms_rony 1-Apr-11 6:41am    
i don't find what iwant in google ...so i put my question here
Sandeep Mewara 1-Apr-11 6:54am    
Oh wow! You don't find when every link speaks of it when you Google... and then you downvote.

Thanks. Carry on with your work. Good attitude! :)
Thanks7872 2-May-13 4:55am    
+5
very good way to deliver the solution, easy to understand thx codeProject and its membranes
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900