There are 2 tables.

The first one has a SerialNo field of type nvarchar , in which eight-digit values ​​are written in the form '20030001', '20030002', etc.

In the second table there is the same SerialNo field, but with the int type (example 30001, 30002).

How to connect tables in a query by the contents of these fields?

    2 answers 2

    I think so (if there are no leading zeros):

    select * from tbl1 a inner join tbl2 b on a.SerialNo = CONCAT('200', b.SerialNo) 

    or so

     select * from tbl1 a inner join tbl2 b on a.SerialNo = 20000000 + b.SerialNo 
    • one
      A small note: it is better not to use such requests on an ongoing basis. They are terribly optimized. - Pavel Mayorov

    Maybe so? SELECT * FROM Table1, Table2 WHERE SUBSTRING(Table1.SerialNo, 4, 5) = CONVERT(nvarchar(8), Table2.SerialNo)

    • 2
      Apparently, it meant something like SUBSTRING (Table1.SerialNo, 4, 5) - msi
    • one
      A small note: it is better not to use such requests on an ongoing basis. They are terribly optimized. - Pavel Mayorov