Alec.
Alec.

Reputation: 5525

SQL Server - Conversion Failed

I'm running a very straightforward bit of SQL and receiving a very strange error with it that I can't seem to explain.

I am getting the following error:

Conversion failed when converting the nvarchar value '20.02.01' to data type int.

Obviosuly I would be looking for something in my query that is trying to convert an nvarchar value to an int, but as you can see below nothing is doing that!

I can't work out why this would be happening.

Please help!

SELECT  R.ReservationsID,
        R.CollectionCompanyName,
        R.CollectionCompanyAddress1,
        R.CollectionCompanyAddress2,
        R.CollectionCompanyTown,
        R.CollectionCompanyPostCode,
        R.DeliveryCompanyName,
        R.DeliveryCompanyAddress1,
        R.DeliveryCompanyAddress2,
        R.DeliveryCompanyTown,
        R.DeliveryCompanyPostCode,
        R.[DeliveryCompanyTel No],
        hw.WasteName,
        hw.WasteTicket,
        hw.SizeName,
        hw.Comments,
        hw.QTY,
        hw.OriginalOrderQty,
        hw.gross,
        hw.tare,
        hw.Net,
        C.PremisesCode,
        pec.EwcCode,
        pec.[Description] 'EWC Desc',
        RI.SICCode,
        lwt.WCode  'EWC',
        R.ActualDeliveryTime,
        R.ActualDeliveryDate



FROM
tblReservation R
LEFT JOIN dbo.tblHazLinesWaste hw ON hw.resid = r.ReservationsID
LEFT JOIN dbo.PdaEwcCode pec ON pec.HazCodeID = hw.EWCCodeID
LEFT JOIN tblCustomer C ON C.CustomerID = R.CustomerID 
LEFT JOIN dbo.tblReservationItems RI ON RI.reservationsID = R.ReservationsID
LEFT JOIN dbo.lookupWasteTypes lwt ON lwt.WCode = RI.EWCCodeID

WHERE
hw.Deleted != 1

Upvotes: 1

Views: 74

Answers (2)

Bacon Bits
Bacon Bits

Reputation: 32170

You've got single quotes for field names: pec.[Description] 'EWC Desc', and lwt.WCode 'EWC',. Those should be double quotes. Single quotes are for string literals.

Beyond that, check your data types for the fields in your ON clauses and the WHERE clause where you're comparing fields.

Upvotes: -1

Stephen Bodine
Stephen Bodine

Reputation: 519

Check your table definitions, do all the ID fls have the same data types? In effect is the reservation ID as string and the hw.resid as bigint or uid?

Upvotes: 2

Related Questions