如何写出能实现以下功能的存储过程?
...
sql4="SELECT count(*) as limit FROM choose where studentid='"& stuid &"' "    
Set Rs4 = Conn.Execute(sql4)
if rs4("limit")>=4 then
Response.Write "<h2>你的实验量已经达到要求,不能再选!</h2>"
else
sql2="SELECT count(*) as lim FROM choose where studentid='"& stuid &"' and week='"& week &"' "    
Set Rs2 = Conn.Execute(sql2)
if rs2("lim")>=2 then
Response.Write "<h2>本周你预约的实验已经达到两个,请另选时间!</h2>"
else
'''''''''''将本日所预约该实验的人数与该实验的套数想比较
sql5="SELECT exnus FROM physics where title='"& title &"' "   
sql6="SELECT count(choosetime) as limsum FROM choose where title='"& title &"' and choosetime='"&sum&"' "  
Set Rs5 = Conn.Execute(sql5)
Set Rs6 = Conn.Execute(sql6)
if rs6("limsum")>=rs5("exnus") then  
Response.Write "<h2>本日该实验已经预约完毕,请另选时间!</h2>"
else
a=false
b=false
rs.movefirst
do while not rs.eof
if rs("title") = request.querystring("title") then
    a=true
end if
if rs("choosetime") = sum  then
    b=true
end if
 rs.movenext
loop
if a=true then
Response.Write "<h2>该实验你已预约!</h2>"
else
if b=true then  
Response.Write "<h2>该时间段你已预约实验!</h2>"
else
if a=false and b=false  then
sql3="INSERT INTO choose (Title,studentid,posttime,choosetime,classroom,week,xingqi,jieci,term) VALUES('" & title & "','" & stuid & "','"& now() &"','" & sum & "','" & classroom & "','" & week & "','" & xingqi & "','" & jieci & "','"& term2 &"')" 
Conn.Execute(sql3) 
Response.Write "<h2>实验预约成功!</h2>"
else
Response.Write "<h2>实验预约无法预约!</h2>"
end if
end if
end if
end if
end if
end if
end if
rs.close