+ -
当前位置:首页 → 问答吧 → 多句sql整理成一句

多句sql整理成一句

时间:2011-12-08

来源:互联网

VBScript code

            set rs=server.CreateObject("adodb.recordset")
            sql = "select  ExamID from Exam_chapter_Test where chapterID="&chapterId&" "
            rs.open sql,Conn,1,3
            do while not rs.eof
                count = Conn.execute("select count(*) from Exam_chapter_Test where ExamID="&rs(0)&" and chapterID<>"&chapterId&"")(0)
                if count=0 then
                    Conn.execute("update Examda_News set DCourseID=0 where ExamID="&rs(0)&"")
                end if
                rs.movenext
            loop
            rs.close
            set rs = nothing

作者: qq80718915   发布时间: 2011-12-08

发错地方鸟
不过你中间的do while里面的,可以全长 if exits来合并

作者: fuxiyang   发布时间: 2011-12-08

两个select 一个UPDATE是不能整合在一起的吧。

作者: fredrickhu   发布时间: 2011-12-08

存储过程?

作者: HJ_daxian   发布时间: 2011-12-08

三条sql没什么共同点

作者: ssp2009   发布时间: 2011-12-08

HTML code
<%

            set rs=server.CreateObject("adodb.recordset")
            sql = "select  ExamID from Exam_chapter_Test where chapterID="&chapterId&" "
            rs.open sql,Conn,1,3
            do while not rs.eof
                    Conn.execute("update Examda_News set DCourseID=0 where ExamID="& rs(0) &" and (select count(*) from Exam_chapter_Test where ExamID="&rs(0)&" and chapterID<>"&chapterId&")>0")
                rs.movenext
            loop
            rs.close
            set rs = nothing

%>

作者: qianjin036a   发布时间: 2011-12-08

如果记录条数不多的话,可以将循环内部的执行字符串赋给一个变量,待循环结束后一次执行.

作者: qianjin036a   发布时间: 2011-12-08

没法合呀,你还有循环呢

作者: pengxuan   发布时间: 2011-12-08