• Register
1 vote

Problem :

I am new to SQL. While trying to execute my JOIN query I am facing below strange error.

“Conversion failed when converting the varchar value to data type int”.

I am unable to figure out why am I getting above error. Can someone help me in fixing the error?

8 5 2
3,230 points

1 Answer

1 vote

Solution :

I am trying to answer your question as I found it interesting.

I think you are a very new to SQL and you are trying to convert the column containing that appears to me as a character values to the int values

As your value is not the valid INT so you are facing above mentioned error. You need to consider many things to avoid such errors.

Is your column supposed to be a char or varchar data type and if that is so then are the non integer characters also expected or allowed in your data?

If this is not the case then:

1.  Have some incorrect data entered by somebody in your test data?

2.  Why this is not the int column to make your DB enforce this thing

If this is the case then why are you casting it to the int?

·  Is your table which you are joining to is also using the integer identifier?

8 4
5,680 points

Related questions

0 votes
1 answer 326 views
Problem : I have the table storing starttime and endtime. I am facing below error: “Conversion failed when converting character string to smalldatetime data type.” While selecting the below query using that table. select CAST(substring(CONVERT(varchar,convert(smalldatetime,o. ... face any error. But, when I select it from a table I got the error. Can somebody help me with this?
asked Jan 20 jwilliam 3.9k points
1 vote
1 answer 71 views
Problem: I am having good exposure to SQL. Currently I want to insert my data from one table to the another table but because of some unknown reason to me I am facing some sorts of issue it shows me below error: Numeric value out of range: 8115 [Microsoft][ODBC ... ,'') AS [TRIM(IngredCost)]  FROM file_5979bd211a3a9` Please help me with this issue. I want to insert all the records in one go.
asked May 23 Martin K 6.6k points
1 vote
1 answer 59 views
Problem: I have very basic knowledge in Sql query writing. I have tried to write the below query. SELECT '$'        + CONVERT(VARCHAR (6), Cast(Avg(TotalPrice) AS NUMERIC (6, 2))) AS 'Average Price',        '$'        + CONVERT(VARCHAR (6), Cast(Min( ... converting numeric to data type varchar". I am unable to find the root cause of above error. Kindly help me in fixing my above sql query.
asked May 23 Martin K 6.6k points
0 votes
1 answer 32 views
Problem : I was getting the following error when running a SQL the conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
asked Nov 12, 2019 peterlaw 6.9k points