I have two tables with lists of files: table1 has column1 with file names that begin with the string ‘STO-‘ followed by a string pattern. So in total, the string has 16 alphanumberic characters (with dashes its a 20-character string).
This is similar to the same file name string found in table2, column1. The issue, however, is that in the first table there are also additional text and characters appended to that 20-digit string. I’m attempting to match results from both tables where those 20-digit character strings match, along with additional information from the table. I’ve found plenty of information about pattern matching within a table, but not comparing two tables. Hopefully I’m explaining myself and can provide an example to help:
TABLE1.Column1 contains a file name ‘STO-100-XX-XXXX-XXXX_Text.pdf ‘
TABLE2.Column2 contains a file name ‘STO-100-XX-XXXX-XXXX.pdf’ and TABLE2.Column3=’Y’
So again, I’m trying to see the list of files from TABLE1 that where the first 20 alphanumeric character string has a match from TABLE2.
(tested on SQL Server 2005, but I believe SUBSTRING is an ANSI SQL function, so should work on most databases).
Also, it’s a little unclear from your question, but if you additionally wanted to restrict the results based on column3, you would simply do