有這樣的sql語句嗎?

gopark 2001-12-11 07:01:45
用一句從兩個表中抓出兩個recordset,並返回.也就是把兩個select用一句返回.
...全文
82 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
knightzhou 2001-12-13
  • 打赏
  • 举报
回复
该范例使用 NextRecordset 方法,查看使用了由三个独立 SELECT 语句组成的复合命令语句的记录集中的数据。

Public Sub NextRecordsetX()

Dim rstCompound As ADODB.Recordset
Dim strCnn As String
Dim intCount As Integer

' 打开复合记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "

Set rstCompound = New ADODB.Recordset
rstCompound.Open "SELECT * FROM authors; " & _
"SELECT * FROM stores; " & _
"SELECT * FROM jobs", strCnn, , , adCmdText

' 显示每一个 SELECT 语句的结果。
intCount = 1
Do Until rstCompound Is Nothing
Debug.Print "Contents of recordset #" & intCount
Do While Not rstCompound.EOF
Debug.Print , rstCompound.Fields(0), _
rstCompound.Fields(1)
rstCompound.MoveNext
Loop

Set rstCompound = rstCompound.NextRecordset
intCount = intCount + 1
Loop

End Sub

gopark 2001-12-12
  • 打赏
  • 举报
回复
Thanks!
panther_totem 2001-12-12
  • 打赏
  • 举报
回复
学习
N_chow 2001-12-12
  • 打赏
  • 举报
回复
可以實現的。
假如你的前端程式是用ADO連的話,可以把兩句Select語句擺在一起,它就會返回兩個Recordset.
例:
Dim rs As New ADODB.Recordset
Dim tmp As New ADODB.Recordset

Dim Conn as New Adodb.Connection
Conn.CursorLocation = adUseClient
Conn.Open "Provider=SQLOLEDB;UID=sa;PWD=;Initial Catalog=Var2000;Data Source=NIPSAN"

rs.Open "Select * From tblStock; Select * From tblStockSub", Conn, adOpenStatic, adLockBatchOptimistic
Set tmp = rs.NextRecordset

MsgBox rs.RecordCount
MsgBox tmp.RecordCount
Set Conn = Nothing
gopark 2001-12-12
  • 打赏
  • 举报
回复
沒有人會嗎?
xyzoem 2001-12-11
  • 打赏
  • 举报
回复
可以用union执行并操作,不过这也只能返回一个recordset
jsidiot 2001-12-11
  • 打赏
  • 举报
回复
两个表有关联才可以那
相关推荐
发帖
MS-SQL Server

3.4w+

社区成员

MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
帖子事件
创建了帖子
2001-12-11 07:01
社区公告
暂无公告