Can a FOR/NEXT type loop be done in a SQL Stored Procedure

I need to code a for next loop in a SQL stored procedure.  I tried joining multiple SELECT statements together but the length of the string is greater then 8000.   Basically the SELECT statement returns the same 3 values, only the where clause changes.  Looking for a value equal to an specific number that is then incremented 10 times, ie WHERE ItemCount = 10,  WHERE ItemCount = 11 etc.  Looking to loop and increcment the value.  I am assignng the results to a temp table and then retreiveing them at the end of the process.

If it is possible what is the syntax?

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DECLARE @counter INT

SET @counter = 1

WHILE @counter <= 10

SELECT A, B, C FROM MyTable WHERE ItemCount= @counter

SET @counter = (@counter + 1)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Here is an approach I use all the time now:

As outlined in the link, you use @@ROWCOUNT immediately after your select statement to gather the data.  Also, in 2008, you can join multiple lines with EXEC(@Data1 + @Data2 + @Data3 + ... + @Data10).  But, even easier is VARCHAR(MAX):
skinsfan99Author Commented:
Thank you!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.