Different query results!
I have a query which returns one set of results when run in SQL Query Analyzer, but only a subset of those results when executed within our application using ADO (not ADO.NET). Obviously this is very strange behaviour, and we would like all our query results to be available in our application.
Would appreciate any assistance.
Cheers,
Fidel
# 3 Re: Different query results!
Please post the code and the query...Really hard to understand the reasons without some code.
What cursor type do you use ?
Hi hspc, thanks for your response. We're using a static cursor to obtain a read-only recordset.
The code which queries the DB is in a VB6 COM+ object, and looks like this:
Public Function RunSQLReturnRS(ByVal QueryString As String, Optional ByVal Params As Variant, Optional ByVal ConnectionStringValue As String) As ADODB.Recordset
' Declare variables
Dim conConnection As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command
' Create objects
Set conConnection = New ADODB.Connection
Set rstRecordset = New ADODB.Recordset
Set cmdCommand = New ADODB.Command
' Init the ADO objects & the stored proc parameters
If ConnectionStringValue = "" Then
conConnection.ConnectionString = mstrConnectionString
Else
conConnection.ConnectionString = ConnectionStringValue
End If
conConnection.Open
With cmdCommand
Set .ActiveConnection = conConnection
.CommandText = QueryString
.CommandType = adCmdText
End With
CollectParams cmdCommand, Params
rstRecordset.CursorLocation = adUseClient
' Execute the query for readonly
rstRecordset.Open cmdCommand, , adOpenStatic, adLockReadOnly
' Disconnect the recordsets and cleanup
Set rstRecordset.ActiveConnection = Nothing
Set cmdCommand.ActiveConnection = Nothing
Set cmdCommand = Nothing
conConnection.Close
Set conConnection = Nothing
' Return the resultant recordset
Set RunSQLReturnRS = rstRecordset
End Function
To execute our query, we call the object from a VBScript ASP page like this:
Set mrstRecordset = mobjDBHelper.RunSQLReturnRS(mstrSQL, Null, Session("ConnectionString"))
The query itself looks like this:
SELECT c.call_id, c.calldate, e.employee_name, co.description,
ca.campaign_name, s.name AS script_name, c.campaign_id, c.script_id,
c.customer_id, c.number_dialled
FROM calls AS c INNER JOIN eControl.dbo.employees AS e
ON c.employee_id = e.employee_id
INNER JOIN calloutcome AS co ON c.calloutcome_id = co.calloutcome_id
LEFT OUTER JOIN campaign AS ca ON ca.campaign_id = c.campaign_id
LEFT OUTER JOIN script AS s ON s.script_id = c.script_id
WHERE c.customer_id = 123456
ORDER BY calldate DESC ;
Hope this is the information you requested.
Regards,
Fidel