Q:

Remove leading zero in join

The tables are:
Table A: tag_num (nvarchar(6))       Table B: tag_num (nvarchar(6))
------------------------------       ------------------------------
883                                  00883

The query:
select * from A test1 
inner join B test2 on test2.tag_num = test1.tag_num

return 0 rows due to the leading zeros in Table B.
How can I return the result
A.tag_num | B.tag_num
883       | 00883

even though Table B column contain leading zeros.
Which data type should I use?

A:

You can cast the columns to int
select * 
from A test1 
inner join B test2 
      on cast(test2.tag_num as int) = cast(test1.tag_num as int)

Or better use int as data type in the table in the first place.

A:

you should cast the string to int and join on them
SELECT *
    FROM A AS test1 INNER JOIN B AS test2 
    ON CAST(test2.tag_num AS INT) = CAST(test1.tag_num AS INT)

