Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Declare @DocEntry nVarchar(10)
SET @DocEntry = (SELECT Convert(nVarchar,Max(U_DocNum),112) FROM [@TI_GoodReceipt])


Select T1.DocDate,T1.DocNum,T1.docentry,t1.CardName,T3.expdate,T1.NumAtCard,T3.notes,T0.BatchNum,T0.Quantity,
T3.DistNumber,t2.WhsCode,t2.U_IsInsp,T2.ItemCode,t2.Dscription,T1.U_BOENO,T2.unitMsr From IBT1 T0
left Join OPDN T1 On T0.BaseType=T1.ObjType
and T0.BaseEntry=T1.DocEntry
inner join pdn1 T2 on T1.DocEntry =t2.DocEntry and T0.quantity <> t2.quantity
left outer join obtn T3 on T0.BatchNum = T3.AbsEntry
where T1.DocEntry = '30'

What I have tried:

Please help me on this query error
Posted
Updated 28-Jul-18 3:18am
Comments
Dave Kreskowiak 28-Jul-18 9:10am    
The reason it fails is because of the "-" character. Since the "-" character occurs somewhere in the middle of the string, instead of at the front of it denoting a negative number, the string is no longer representing an integer value.

If you think that string represents "1819000030 minus 1", think again. Conversion to INT will not interpret the string that way and will not do the math for you.
RedDk 28-Jul-18 14:22pm    
What is "IBT1" and what is it's relationship to "T0"?

Look at the error message:
Conversion failed when converting the nvarchar value '1819000030-1' to data type int.
It's not an integer, so when SQL tried to convert it it fails.

Why isn't it an integer? Dunno - it's your data after all and we have no access to it.
So start by finding out where the value '1819000030-1' is coming from, and then you can start working out which part of your query is trying to convert it. Then you can decide if there is a table design error, a data error, or a query error.

But we can't do that for you - we have no access to your data at all!
 
Share this answer
 
Quote:
Conversion failed when converting the nvarchar value '1819000030-1' to data type int.

Bacause '1819000030-1' is not an integer, '-' is allowed only in first position for negative numbers.
It should be obvious to everyone.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900