Click to See Complete Forum and Search --> : LIKE between 2 fields on 2 different tables


mproper
09-13-2007, 10:47 AM
First time poster, so please go easy...

I have two tables in SQL Server 2000. The first table contains filenames. The second table contains a field with a bunch of HTML in it. I need to find out which files in Table1 are NOT used in the HTML in Table2. Basically trying to find out which files on our server are not being used on any webpages.

Example:
Table1.FileName
MyImage001.jpg
MyImage002.jpg
UnusedImage.jpg

Table2.HTML
Img Src="MyImage001.jpg"
Img Src="MyImage002.jpg"

Expected Results
UnusedImage.jpg

Here is what I came up with, but does not work obviously:


SELECT Table1.FileName
FROM Table1, Table2
WHERE Table2.HTML NOT LIKE '%' + Table1.FileName + '%'


I only need to run this once, so performance is not an issue (as long as it doesn't time out, I mean)

mattyblah
09-13-2007, 03:09 PM
use the patindex function. it will return > 0 if a match is found.


select patindex('%' + 'MyImage001.jpg' + '%', 'Img Src="MyImage001.jpg"')