关于sqlserver存储过程循环
举个例子,用ASP写的
Set rs = conn.execute ("Select id,name from Table")
Do while not rs.eof
Set rs2 = conn.execute ("Select userid,school from Table2 where userid = "&rs("id") )
dim gets = ""
Do while not rs2.eof
gets = gets&rs2("school")&"<br>"
rs2.movenext
Loop
rs.movenext
loop
response.write gets
请问用存储过程怎么写?一定要用游标吗?
[解决办法]
一个递规查询变量,连表解决问题.
declare @str varchar(8000)select @str=isnull(@str,'') + "<br/>" + b.school from [table] ainner join table2 b on a.id=b.useridselect stuff(@str,1,5,'')
[解决办法]
存储过程只能用游标了!!