Click here to Skip to main content
15,899,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I am newbie to SQL programming and encountering and issue in one of live site.

I have the following SQL error in the log file.

Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the nvarchar value '2686000.75' to data type int.
Error Code: 245
Call: SELECT t0.DFY004_MDL_D, MAX(CAST(t1.DFY006_ATTR_VAL_X AS int)), MIN(CAST(t1.DFY006_ATTR_VAL_X AS int)) FROM VDFY006_DERTV_ATTR t1 LEFT OUTER JOIN VDFY003_DERTV t0 ON (t1.DFY003_DERTV_D = t0.DFY003_DERTV_D) WHERE (((((t0.DFY004_MDL_D IN (?,?,?,?,?)) AND (t1.DFY005_ATTR_D = ?)) AND (t1.DFY006_ATTR_VAL_X IS NOT NULL)) AND (t1.DFY006_IS_DEL_F = ?)) AND (t0.DFY014_STAT_D = ?)) GROUP BY t0.DFY004_MDL_D
bind => [8 parameters bound]
Query: ReportQuery(referenceClass=DerivativeAttribute sql="SELECT t0.DFY004_MDL_D, MAX(CAST(t1.DFY006_ATTR_VAL_X AS int)), MIN(CAST(t1.DFY006_ATTR_VAL_X AS int)) FROM VDFY006_DERTV_ATTR t1 LEFT OUTER JOIN VDFY003_DERTV t0 ON (t1.DFY003_DERTV_D = t0.DFY003_DERTV_D) WHERE (((((t0.DFY004_MDL_D IN ?) AND (t1.DFY005_ATTR_D = ?)) AND (t1.DFY006_ATTR_VAL_X IS NOT NULL)) AND (t1.DFY006_IS_DEL_F = ?)) AND (t0.DFY014_STAT_D = ?)) GROUP BY t0.DFY004_MDL_D")

Need help to understand the issue and steps to resolve this.

What I have tried:

SQL Server Helper[^]


[^]
Posted
Updated 23-Feb-18 0:24am
v2

1 solution

"Conversion failed when converting the nvarchar value '2686000.75' to data type int"

The problem is pretty clear: you have a column in the database whose type is integer (int), and you are trying to feed it with a string (nvarchar) (moreover, this string value does not represent an integer value itself, but rather a floating-point value).

You should realize the importance of data types, how they are related, and how you have to manage them.
 
Share this answer
 
Comments
Member 13692486 23-Feb-18 5:28am    
Ok
but as per the DB structure I am not sure where the ncharvalue is coming from. Is there and SQL query script that can help me locate '2686000.7'
phil.o 23-Feb-18 5:36am    
It most probably comes from one of the columns whose content you are trying to cast to integer in your SQL resquest.
But you have a bigger problem imo: you are storing floating-point values as nvarchar in your database. Always use the right data type.
There is no preexisting script which can spot a value in any column of any table of a database. You have access to your database schema; inspect it; everywhere you are using nvarchar type instead of a numeric one to store numeric values, your design is flawed. Only you can do that, because only you have access to the full database schema and data.

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