I have two tables, with different columns that I would like to compare. There is an issue in our system with serial numbers, and I want to make sure that all of the serial numbers (CMMTTEXT
- in comma delimitted form) in Table B are being transferred to Table A (SERLTNUM
- where each individual serial number has its own line)
Basically, what I would like to try and do is take the SOPNUMBER
's from the last 3 months (which I would get from Table C), then get all rows from Table B and Table A with the last 3 months SOPNUMBER
's and then somehow to make sure all serial numbers in CMMTTEXT
in Table B are in Table A as SERLTNUM
.
I know how to get all of the data, but I'm not sure what I can do in order to compare the two columns in SQL when they have different data formats. I am trying to think if there is someway I can just use substr()
to search CMMTTXT
but don't know how I could then display rows where there was no match found.
The LNITMSEQ
table is an ID that corresponds to different line items in an order.
Table A
+-----------+----------+----------+---------------+
| SOPNUMBER | LNITMSEQ | SERLTNUM | ITEMNMBR |
+-----------+----------+----------+---------------+
| I327478 | 16384 | ABC123 | someItem |
+-----------+----------+----------+---------------+
| I327478 | 32768 | DEF123 | someOtherItem |
+-----------+----------+----------+---------------+
Table B
+-----------+----------+-----------------------------+
| SOPNUMBER | LNITMSEQ | CMMTTEXT |
+-----------+----------+-----------------------------+
| I327478 | 16384 | ABC123,ABC124,ABC125,ABC126 |
+-----------+----------+-----------------------------+
| I327478 | 32768 | DEF123,DEF124,DEF125,DEF126 |
+-----------+----------+-----------------------------+
Table C
+-----------+-----------+
| SOPNUMBER | DATE |
+-----------+-----------+
| I327478 | 5/20/2017 |
+-----------+-----------+
| I327479 | 5/21/2017 |
+-----------+-----------+