question

akhterhussain-3167 avatar image
0 Votes"
akhterhussain-3167 asked TomZika answered

Error converting data type varchar to float.

Below is query,



 SELECT sum(isnull(Convert( float,Rec.Sell_Amt ),0))-sum(isnull(convert(float ,Pr.Rec_Amt ),0))as Amt,Pr.Level_Four_ID
 FROM     tbl_Receivable_Customer AS Rec
 left outer join tbl_Received_Amount Pr 
 on Pr.Sell_ID=Rec.Sell_ID
    
 where rec.Sell_Del is null and pr.Sell_Del is null
    
 group by pr.Level_Four_ID
sql-server-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TomZika avatar image
1 Vote"
TomZika answered

What is the error (number and message)?
We don't have access to your table definitions and data, so we cannot replicate the issue.

My guess is that the varchar column container other than numeric data.
You can find them by using

 WHERE TRY_CAST([yourVarcharCol] as float) IS NULL

TRY_CAST documentation:
https://docs.microsoft.com/en-us/sql/t-sql/functions/try-cast-transact-sql?view=sql-server-ver15

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.