7,763
社区成员
发帖
与我相关
我的任务
分享
SELECT id FROM (SELECT 1 id UNION SELECT 2 UNION SELECT 3) t FOR XML PATH ('')
<id>1</id><id>2</id><id>3</id>
Option Explicit
Private Sub Command1_Click()
Dim ct As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim s As String
On Error GoTo eh
s = "SELECT id FROM (SELECT 1 id UNION SELECT 2 UNION SELECT 3) t FOR XML PATH ('')"
ct.Open "Persist Security Info=True;Provider=SQLOLEDB.1;User ID=sa;Password=pwd;Data Source=server;Initial Catalog=test"
Set rs = ct.Execute(s)
Debug.Print rs.Fields(0).Name
Debug.Print rs.Fields(0).Value
Set rs = Nothing
Set ct = Nothing
Exit Sub
eh:
MsgBox Err.Description, , Err.Number
End Sub