Skip to content
Advertisement

How to convert varchar column values into int?

I have a column toysid which is of varchar datatype in one table. Also another table having same the column toysid with int datatype (I know I can modify column for first table but I have to follow some procedure to keep it as varchar).

I have written following query to join the table:

The query returns error:

Conversion failed wher converting varchar datatype into int

Hence I have tried below query:

I got the same error. How to convert it? I have searched in many websites but I’m unable to get solution. Please anyone help on this.

Advertisement

Answer

You can omit such records which having non-numeric value and then cast with integer like below:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement