首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于sqlserver存储过程循环,该如何解决

2012-01-26 
关于sqlserver存储过程循环举个例子,用ASP写的Set rs conn.execute (Select id,name from Table)Do wh

关于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

请问用存储过程怎么写?一定要用游标吗?

[解决办法]
一个递规查询变量,连表解决问题.

SQL code
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,'')
[解决办法]
存储过程只能用游标了!!

热点排行