Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing fields with LIKE

Status
Not open for further replies.

bob120579

Programmer
Feb 9, 2005
42
US
How do I compare a field with part of another field? For example I want to know what filenames are included in file path names...

If I had a filename (2008file.pst) column in table A and wanted to know if it was included in any records in the path (C:\Folder\2008file.pst) field of table B, how can that be accomplished in a select?

Thanks
 
The first query that comes to mind is

select * from myTable where FilePath like '%' + @FileName + '%'
 
Not completely tested:

Code:
Create table #TestIT(Column1 Varchar(4), Column2 varchar(10))
insert into #TestIt(column1,column2) Values('abc','zzzabcxxx')
insert into #TestIt(column1,column2) Values('ccc','zzzabcxxx')


SELECT CASE CHARINDEX(Column1,Column2)
WHEN 0 THEN 'Not Found'
ELSE 'Found'
END
from #TestIT

drop table #TestIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top