Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Looping in a Stored Procedure

Author  Topic 

kathyc2003
Starting Member

15 Posts

Posted - 2008-02-03 : 11:41:59
Hello,

I am trying to creating a while loop.
I have created a variable called @MyCount
which I initially set to 1.

For each iteration of the loop, I would
like the value of @MyCount to increase by 1.

What am I doing wrong?


WHILE ( @MyCount <= @DaysInMonth )
BEGIN

/* put some code in here *./

@MyCount = @MyCount + 1
END


Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-03 : 12:43:58
quote:
Originally posted by kathyc2003

Hello,

I am trying to creating a while loop.
I have created a variable called @MyCount
which I initially set to 1.

For each iteration of the loop, I would
like the value of @MyCount to increase by 1.

What am I doing wrong?


WHILE ( @MyCount <= @DaysInMonth )
BEGIN

/* put some code in here *./

SET @MyCount = @MyCount + 1
END


Thanks




Use SET to assign new value to count variable
Go to Top of Page

subrata4allfriends
Starting Member

24 Posts

Posted - 2008-02-03 : 13:08:55
As per sql server syntax u have to declare a variable then set the value what value u want to assign to it.

DECLARE MyCount INT
SET @MyCount = @MyCount + 1

Thanks & Regards,
4allfriends.

"Life is not a bed of roses."
Go to Top of Page
   

- Advertisement -