Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Like Operator Exact Match Question

Author  Topic 

danasegarane76
Posting Yak Master

242 Posts

Posted - 2014-03-14 : 02:00:02
Hi Team,
I am using like operator to get some results

And the data looks like

CountryCodes
503:51,880:51,936:51,952

And when I use like

Select * from table where CountryCodes like '%503:5%'
This gets the above set results. But I want to match the exact text .

This means that need to get the result only if
503:5,880:51,936:51,952

Any way to this

nagino
Yak Posting Veteran

75 Posts

Posted - 2014-03-14 : 02:18:01
Like Following ?

Select * from table where CountryCodes like '%503:5,%' or CountryCodes like '%503:5'

-------------------------------------
From Japan
Sorry, my English ability is limited.
Go to Top of Page

danasegarane76
Posting Yak Master

242 Posts

Posted - 2014-03-14 : 02:22:13
Yes, I tried this and this looks like working with one issue.

I can see the search functionality using a common function where %% append is added globally.

I would like to something like

Select * from table where CountryCodes like '%503:5[\,]%'

where the last , may or may not exist there.

Any way to handle this
Go to Top of Page

nagino
Yak Posting Veteran

75 Posts

Posted - 2014-03-14 : 02:41:20
Select * from table where CountryCodes + ',' like '%503:5,%'

-------------------------------------
From Japan
Sorry, my English ability is limited.
Go to Top of Page
   

- Advertisement -