The error is happening because you are converting a value that does not fit the type INT
, then ends up giving overflow
in conversion. No SQL Server
, there are 4 types of variables to treat integers, they are they: TINYINT
, SMALLINT
, INT
and BIGINT
.
Below follows the maximum values supported by these types:
- TINYINT: 0 to 255.
- SMALLINT: -32,768 to 32,767.
- INT: -2,147,483,648 to 2,147,483,647
- BIGINT: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
So, to solve your problem, try to run the QUERY
thus:
SELECT
controle.num_aut ,
estoque.cod_autorizacao
FROM cad_controle AS controle
INNER JOIN estoque AS estoque WITH ( NOLOCK )
ON CONVERT ( BIGINT , estoque.cod_autorizacao ) = CONVERT ( BIGINT , controle.num_aut )
Editing:
When executing the query, if you come across this error message: "Error converting data type varchar to bigin"
, then there is probably a value não numérico
in any of the columns, to solve this case, try to run the query below, to fix this problem, only that way, talvez
your INNER JOIN
doesn’t work the way you want it to.
SELECT
controle.num_aut ,
estoque.cod_autorizacao
FROM cad_controle AS controle
INNER JOIN estoque AS estoque WITH ( NOLOCK )
ON
( CASE WHEN ( ISNUMERIC ( estoque.cod_autorizacao ) = 1 ) THEN CONVERT ( BIGINT , estoque.cod_autorizacao ) ELSE 0 END ) =
( CASE WHEN ( ISNUMERIC ( controle.num_aut ) = 1 ) THEN CONVERT ( BIGINT , controle.num_aut ) ELSE 0 END )
The ideal would be to compare everything as varchar same,
num_aut
is of fixed size? for example always has 10 digits,12345
flipped0000012345
– rray
Maybe bigint. The error message says that the number is too big for the int type.
– bfavaretto
@rray the 2 fields are varchar(50)
– Shaolin Fantastic
@bfavaretto tried to convert to bigint and This error appeared: Error Converting data type varchar to bigint
– Shaolin Fantastic
@Shaolymphantastic This error must be appearing probably because the column has some value that is not numerical.
– FabianoLothor