P
pietlinden
Just wondering... If I write a query using MINUS or INTERSECT, can ADO
execute it if I'm running it within Access?
I have two union-compatible sets and I want to return this result:
(A union B) minus (A intersect B)
(if you do a Venn diagram, it's the parts of A and B that do not
overlap.)
Here's the test:
Public Sub TestADOUnmatched()
Dim strSQL As String
Dim rs As ADODB.Recordset
strSQL = "(SELECT t1.PatientID, t1.Toxicity, t1.Cycle, t1.Grade
FROM t1 UNION ALL "
strSQL = strSQL & "SELECT t2.PatientID, t2.Toxicity, t2.Cycle,
t2.Grade FROM t2) MINUS "
strSQL = strSQL & "(SELECT t1.PatientID, t1.Toxicity, t1.Cycle,
t1.Grade FROM t1 INTERSECT "
stsrql = strSQL & "SELECT t2.PatientID, t2.Toxicity, t2.Cycle,
t2.Grade FROM t2);"
Debug.Print strSQL
Set rs = New ADODB.Recordset
rs.Open strSQL, CurrentProject.Connection, adOpenStatic,
adLockReadOnly
Do Until rs.EOF
Debug.Print rs.Fields("PatientID"), rs.Fields("Toxicity"),
rs.Fields("Cycle"), rs.Fields("Grade")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
When I run it, I get "Syntax error in union query" -214746259
(80004005)... so I guess ADO doesn't support it...
I'm writing the query this way because any of the following can be
true;
1. a record is in one of the tables but not the other.
2. either cycle or grade can be wrong.
I guess I'll try it in SQL Server later and see if it works, and see
if it's the SQL that Access doesn't like that SQL Server does...
any thoughts? (Oh, and if you're reading this Aaron, I don't need the
standard rant. I'm just trying to get my head around some of the
differences between the Access query engine and the SQL Server query
engine.)
Thanks,
Pieter
Thanks
Pieter
execute it if I'm running it within Access?
I have two union-compatible sets and I want to return this result:
(A union B) minus (A intersect B)
(if you do a Venn diagram, it's the parts of A and B that do not
overlap.)
Here's the test:
Public Sub TestADOUnmatched()
Dim strSQL As String
Dim rs As ADODB.Recordset
strSQL = "(SELECT t1.PatientID, t1.Toxicity, t1.Cycle, t1.Grade
FROM t1 UNION ALL "
strSQL = strSQL & "SELECT t2.PatientID, t2.Toxicity, t2.Cycle,
t2.Grade FROM t2) MINUS "
strSQL = strSQL & "(SELECT t1.PatientID, t1.Toxicity, t1.Cycle,
t1.Grade FROM t1 INTERSECT "
stsrql = strSQL & "SELECT t2.PatientID, t2.Toxicity, t2.Cycle,
t2.Grade FROM t2);"
Debug.Print strSQL
Set rs = New ADODB.Recordset
rs.Open strSQL, CurrentProject.Connection, adOpenStatic,
adLockReadOnly
Do Until rs.EOF
Debug.Print rs.Fields("PatientID"), rs.Fields("Toxicity"),
rs.Fields("Cycle"), rs.Fields("Grade")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
When I run it, I get "Syntax error in union query" -214746259
(80004005)... so I guess ADO doesn't support it...
I'm writing the query this way because any of the following can be
true;
1. a record is in one of the tables but not the other.
2. either cycle or grade can be wrong.
I guess I'll try it in SQL Server later and see if it works, and see
if it's the SQL that Access doesn't like that SQL Server does...
any thoughts? (Oh, and if you're reading this Aaron, I don't need the
standard rant. I'm just trying to get my head around some of the
differences between the Access query engine and the SQL Server query
engine.)
Thanks,
Pieter
Thanks
Pieter