同一个表中
sql1="select * from TableA where ontop=true"
sql2="select * from TableA where ontop=false"
set rs=conn.execute(sql1&";"&sql2)
这样只能获得第一条SQL的数据,如何才能获得全部数据呢
...全文
48425打赏收藏
同时执行两条SQL语句,如何读取数据
同一个表中 sql1="select * from TableA where ontop=true" sql2="select * from TableA where ontop=false" set rs=conn.execute(sql1&";"&sql2) 这样只能获得第一条SQL的数据,如何才能获得全部数据呢
思路:
如果要选出100条数据
1.sql1="select * from TableA where Ontop=true order by ID DESC"
2.执行这条SQL语句,显示出数据.用一个变量count_num存储rs.recordcount
3.用100减去count_num
4.sql1="select top "&100-count_num&" * from TableA where Ontop=false order by ID DESC"
5.接着执行这个SQL
===========================
一条就可以读出来了
sql1="select * from TableA where ontop=true or Ontop=false"
也可以试试
sql1="select * from TableA where ontop=true"
union all
sql2="select * from TableA where Ontop=false "
===============================
1、sql1="select * from TableA where ontop=true or Ontop=false"的办法不是我需要的
思路:
如果要选出100条数据
1.sql1="select * from TableA where Ontop=true order by ID DESC"
2.执行这条SQL语句,显示出数据.用一个变量count_num存储rs.recordcount
3.用100减去count_num
4.sql1="select top "&100-count_num&" * from TableA where Ontop=false order by ID DESC"
5.接着执行这个SQL
====================================================
Do Until rs Is Nothing
If rs.State = AdStateOpen Then ''这句报错
While Not rs.EOF
.........
Wend
End If
Set rs = rs.NextRecordset
Loop
不一样哦:D
我把SQL语句写完整点
sql1="select top 3 * from TableA where Ontop=true order by ID DESC"
sql2="select top 7 * from TableA where Ontop=false order by ID DESC"
如果TableA中有100行,其中有10行是Ontop=true,
如果用"select top 10 * from TableA"可能一条Ontop=true的行都读不出来,
因为排序时一般用时间和ID排序,这10行Ontop=true的可能排在最底下
谢谢,如果有N条SQL语句,如何才能判断有多少个rs呢?
====================================================
Do Until rs Is Nothing
If rs.State = AdStateOpen Then
While Not rs.EOF
.........
Wend
End If
Set rs = rs.NextRecordset
Loop