SQLTeam.com | Weblogs | Forums

【help】t-sql in like clause


#1

Hi All,

In my column (FilePath) contains the values as below,
FILEPATH

\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C12\29P
\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C122\207
\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C124\212
\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C127\252

If my SQL as below,

select * from TRFile where FilePath LIKE '%\\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C12%' order by FileName 

It will return all the values with contains 'C12' and this is wrong.

I need the result only return ONE record which is

\\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C12

Any idea?


#2

LIKE 'path\C12%'


#3

If you just want the first (best) match:

select top (1) *
from TRFile
where FilePath LIKE '%\Dpo-doctest1\Citibank Files\Citibank\07-JULY\20150703\C12%'
order by FileName