简体   繁体   中英

SQL LIKE from another table

I have two tables:

Table1 with the column customerName in string:

1,2,3,101,102,customerA,customerB.

Table 2 with the changeID in string:00001,00002,00101,customerA.

Now I want to join these two tables, because I know changeID 00001 is customer 1, changeID 00101 is customer 101 and changeID customerA is off course customerA, but due to the zeroes I tried to use LIKE but failed.

Do you guys have Idee how to join these two tables?

You can use an old "where join":

Select Table1.*, Table2.*
From Table1, Table2
Where Table1.ID = Val(Table2.ChangeID)

or:

Select Table1.*, Table2.*
From Table1, Table2
Where Right("0000" & Table1.ID, 5) = Table2.ChangeID

If that is too slow, write either of the tables to temporary table where the final ID and ChangeID will have matching data types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM