Hi
We have a filed called Ouref that usually held information like this 110445. Our systems have now change this so it as a prefix like this Journey: 110445, the SP is included.
It is now not bringing in the new Orrref and also not supplying the PurchaseOrderNumnbers now. I have taken out the
--where IsNumeric(Ourref) = 1
--and LEN(Ourref) < 8
It then is coming up with
Msg 245, Level 16, State 1, Line 14
Conversion failed when converting the varchar value 'FX05 DXT' to data type int.
I have tried to convert the Ourref from varchar to int but I am going round in circles. COuld someon please put me right on the coding please, so I can get it working again. Thanks in advance
We have a filed called Ouref that usually held information like this 110445. Our systems have now change this so it as a prefix like this Journey: 110445, the SP is included.
It is now not bringing in the new Orrref and also not supplying the PurchaseOrderNumnbers now. I have taken out the
--where IsNumeric(Ourref) = 1
--and LEN(Ourref) < 8
It then is coming up with
Msg 245, Level 16, State 1, Line 14
Conversion failed when converting the varchar value 'FX05 DXT' to data type int.
I have tried to convert the Ourref from varchar to int but I am going round in circles. COuld someon please put me right on the coding please, so I can get it working again. Thanks in advance
SQL:
USE [Main DB]
GO
/****** Object: StoredProcedure [dbo].[148-POjourneyinfo] Script Date: 08/02/2021 12:23:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[148-POjourneyinfo]
@Fromjourneydate datetime,
@Tojourneydate datetime
AS
select Ourref, max(PurchaseOrderID) as PurchaseOrderID,
PurchaseOrderNumber
into #iantab
from PurchaseOrderHeader
where IsNumeric (Ourref) = 1
and LEN(Ourref) < 8
group by OurRef, PurchaseOrderNumber
SELECT
IRT.OurRef, IRT.PurchaseOrderNumber,
dbo.JourneyHeader.JourneyDate, dbo.Vehicle.Name, dbo.JourneyHeader.DriverName, dbo.JourneyHeader.VehicleName,
dbo.JourneyHeader.JourneyNumber, dbo.JourneyHeader.TotalVolume, dbo.JourneyLine.DropNumber, dbo.OrderHeader.DeliveryAddress,
dbo.Customer.Name AS [Customer Name], dbo.Customer.County, dbo.Customer.PostCode, dbo.JourneyHeader.NoOfStops, dbo.OrderHeader.udfSalesOrderOTIF,
dbo.JourneyHeader.NoOfPacks, dbo.JourneyHeader.udfLoader1, dbo.JourneyHeader.udfLoader2, dbo.JourneyHeader.TransportCost, dbo.JourneyHeader.TripMileage
FROM dbo.JourneyHeader INNER JOIN
dbo.JourneyLine ON dbo.JourneyHeader.JourneyID = dbo.JourneyLine.JourneyID INNER JOIN
dbo.Vehicle ON dbo.JourneyHeader.VehicleID = dbo.Vehicle.VehicleID INNER JOIN
dbo.OrderHeader ON dbo.JourneyLine.OrderID = dbo.OrderHeader.OrderID INNER JOIN
dbo.Customer ON dbo.OrderHeader.CustomerID = dbo.Customer.CustomerID
left join #iantab AS IRT on dbo.JourneyHeader.JourneyNumber = IRT.OurRef
WHERE dbo.JourneyHeader.JourneyDate between @Fromjourneydate and @Tojourneydate
ORDER BY dbo.JourneyHeader.JourneyNumber