1

Topic: Request about comparing of the data

Kind day!
There are two tables containing an INN.
In the first table of an INN it is written down in the form of number (type bigint); in the second - in the form of the text (type varchar), that is in value are available both leading zero and characters a gap and other. It is necessary to deduce in a resultant dial-up matching values (an INN which meet in both tables).
I made here such request:
select inn_1.inn from inn_1 where inn_1.inn = (select cast (inn_2.inn as bigint) from inn_2)
As a result produces an error: the Message 8114, level 16, a state 5, a line 1
Error at type conversion of the data varchar to bigint.
Prompt please where an error in request?

2

Re: Request about comparing of the data

Begin with

select inn from inn_2 where isnumeric (inn) =0 and nullif (inn, ") is not null

3

Re: Request about comparing of the data

SELECT inn from inn_2
WHERE TRY_CAST (INN AS BIGINT) IS NOT NULL

4

Re: Request about comparing of the data

Prolog;
In advance I apologize for a silly question, as they say I just study. But I correctly understand, what your request allows to receive sampling of table 2 of that INN which unambiguously cannot be transformed to numerical type?

5

Re: Request about comparing of the data

xenix, Thanks big. Works.
Truth not so I understand than cast differs from try_cast

6

Re: Request about comparing of the data

1988;
I should  :-) - have a look help. If it is short, CAST (' Evgenija1988 ' AS INT) falls with "can not convert varchar to int";
And TRY_CAST returns NULL

7

Re: Request about comparing of the data

xenix, very refined harm which goes to the blessing)))) thanks, you very much helped me)