MS SQL server for a long time.
Client has moved to a new cloud based server and a few stored procedures
are not returning anything. This is a later version of MS SQL Server
In debug I can see the result of
isResultSet = JDBC_execCall( prepStmt )
Is 0
So I added a call to get the update count as
if isresultSet = *OFF;
rc = JDBC_getUpdateCount( prepstmt );
endif;
This returns a value of 16817. This does match the number of records
written to the temporary tables before the SP runs the query that should
return the result set.
So the JDBC call is interpreting the result as an update count and not a
result set.
I tried adding IsResultSet = JDBC_getMoreResults( prepstmt ); checking
the possibility of more than one result set being returned but again 0 is
returned.
What I am not understanding is how to code the stored procedure that used
temp tables to return the result set.
The SP has worked previously but that was on an older version of MS SQL
server and when the server was locally in house and not in the cloud.
If I run the query manually within MS SQL Management Studio it returns the
correct list.
We have the following JDBC jar files installed
sqljdbc.jar
sqljdbc4.jar
Not sure how to tell the actual version ?
Here is the SQL that we are getting the update count back from where we actually want the result set.
Code: Select all
declare @StartDate datetime = '2023-07-01'
declare @EndDate datetime = '2023-08-01'
declare @OperatorID int = 82
create table #jobs (
CarNumber varchar(50),
Fare money,
Tolls money
)
create table #shifts (
CarNumber varchar(50),
LogonTime datetime,
LogoffTime datetime,
[Minutes] int,
Kilometres int,
Offered int,
Accepted int,
Rejected int,
Recalled int,
Completed int
)
insert into #jobs
select VH.CarNumber as [CarNumber],
TD.ChargesPrice + TD.ChargesFlagfall + TD.ChargesExtras + TD.Tolls
- TD.Discount as [Fare],
TD.Tolls as [Tolls]
from TaxiHistory.dbo.VehicleJobHistory VJ with (nolock)
inner join TaxiHistory.dbo.tblDispatch TD with (nolock) on VJ.BookingID = TD.BookingID
inner join TaxiHistory.dbo.Vehicle VH with (nolock) on VJ.VehicleID = VH.VehicleID
inner join (select distinct VehicleID, StartDate
from TaxiHistory.dbo.VehicleOwnerOperatorHistory
where OwnerOperatorID = @OperatorID
and OwnerOperatorTypeID = 2
and StartDate < getdate()
and (EndDate is null or EndDate > getdate())) as OH on VJ.VehicleID = OH.VehicleID
and VJ.TimeCarCompletedJob > OH.StartDate
where VJ.TimeCarCompletedJob between @StartDate and @EndDate
and TD.StatusID = 7
insert into #shifts
select VH.CarNumber as [Car Number],
DL.LogonTime as [Logged On],
DL.LogoffTime as [Logged Off],
datediff(minute,DL.LogonTime,DL.LogoffTime) as [Minutes],
isnull(DL.KMsAvailablePlotted + DL.KMsNotAvailable +
DL.KMSOnWayToJobs,0) as [Kilometres],
isnull(DL.JobsOffered,0) as [Jobs Offered],
isnull(DL.JobsAccepted,0) as [Jobs Accepted],
isnull(DL.JobsRejected,0) as [Jobs Rejected],
isnull(DL.JobsRecalled,0) as [Jobs Recalled],
isnull(DL.JobsCompleted,0) as [Jobs Completed]
from TaxiHistory.dbo.DriverLogon DL with (nolock)
inner join TaxiHistory.dbo.Vehicle VH with (nolock) on VH.VehicleID = DL.VehicleID
inner join (select distinct VehicleID, StartDate
from TaxiHistory.dbo.VehicleOwnerOperatorHistory
where OwnerOperatorID = @OperatorID
and OwnerOperatorTypeID = 2
and StartDate < getdate()
and (EndDate is null or EndDate > getdate())) as OH on DL.VehicleID = OH.VehicleID and
DL.LogonTime > OH.StartDate
where DL.LogonTime between @StartDate and @EndDate
select SH.[Car Number],
SH.[Hours],
SH.[Kilometres],
SH.[Jobs Offered],
SH.[Jobs Accepted],
SH.[Jobs Rejected],
SH.[Jobs Recalled],
SH.[Jobs Completed],
JB.[Total Fares],
JB.[Total Tolls]
from (select S.CarNumber as [Car Number],
isnull(sum(S.[Minutes])/60,0) as [Hours],
isnull(sum(S.Kilometres),0) as [Kilometres],
isnull(sum(S.Offered),0) as [Jobs Offered],
isnull(sum(S.Accepted),0) as [Jobs Accepted],
isnull(sum(S.Rejected),0) as [Jobs Rejected],
isnull(sum(S.Recalled),0) as [Jobs Recalled],
isnull(sum(S.Completed),0) as [Jobs Completed]
from #shifts S
group by S.CarNumber) as SH inner join (select
J.CarNumber as [Car Number],
sum(J.Fare) as [Total Fares],
sum(J.Tolls) as [Total Tolls]
from #jobs J
group by J.CarNumber ) as JB on SH.[Car Number] = JB.[Car Number]
order by SH.[Car Number]
drop table #jobs
drop table #shifts
Thanks
Don