So basically, I have two table, X and Y. I want to join them with the substring-ed value but I'm unsure of how I can do so.
Sample code of X:
select distinct
trim(ws.WS_name) as [WS Name],
substring(trim(e.equip_id),1,8) as [Equid ID],
into #eqm_hist
from eqmhist
Sample table of X:
WS name | Equid ID |
---|---|
WS 21 | KTRGAF7L |
WS 21 | KTRGAF7L |
Sample code of Y:
select distinct
[Batch ID],
[Qty],
rtrim(flh.tracking_interface_id) as [Tool],
[WS Name],
into #main
from flh
Sample table of Y:
Batch ID | Qty | Tool |
---|---|---|
12345 | 100 | KTRGAF7L00 |
23456 | 100 | KTRGAF7L00 |
Do note that [Tool] and [Equid ID] is the same
How can I join them together using the substring-ed values to achieve the table like below? Do I also have to remove the last two digit for [Tool] in table Y to do so?
Batch ID | Qty | Tool | WS Name |
---|---|---|---|
12345 | 100 | KTRGAF7L00 | WS 21 |
23456 | 100 | KTRGAF7L00 | WS 21 |