all groups > sql server programming > february 2006 >
You're in the

sql server programming

group:

izzit got for loop in transact-sql stored procedure



izzit got for loop in transact-sql stored procedure yokesanhoo NO[at]SPAM gmail.com
2/20/2006 9:22:40 PM
sql server programming: Dear all,
i was confuse that izzit there are sql server was support for loop
statement,
i got one section of inner query in my asp program, and i would like
to change in to stored procedure,i using ms sql server as my database.
the following is the asp code with the inner sql

For i = 1 To 10
If not fixQuote(Request.Form("txtDescription" & i)) = "" Then
strSQL = "INSERT INTO ack_item
(Ack_id,Part_no,Serial_no,Description,Qty,Itm) VALUES ("& strAckID
&",'"& fixQuote(Request.Form("txtPartNo" & i)) &"',"
strSQL = strSQL & "'"& fixQuote(Request.Form("txtSerialNo" & i))
&"','"& fixQuote(Request.Form("txtDescription" & i)) &"',"&
CheckComma(Request.Form("txtQty" & i)) &","
strSQL = strSQL & "'"& fixQuote(Request.Form("txtItm" & i)) &"')"
call SetConnection(strSQL,2)
End If
Next

could i change whole code into the sql server (store procedure)?
Re: izzit got for loop in transact-sql stored procedure Uri Dimant
2/21/2006 12:00:00 AM
Hi
Yep , there is a WHILE loop in the SQL Server

DECLARE @i INT
SET @i=1
WHILE @i<=10
BEGIN
---Do something here

SET @i=@i+1
END

Can you elaborate a little bit what you are doing so we can suggest a
solution without using a loop?




[quoted text, click to view]

AddThis Social Bookmark Button