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)
 find character in string

Author  Topic 

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2013-04-08 : 13:27:14
I have a field that contains a string such as
A;D;G;F


Within that string I want to search for a specific character which is passed as a parameter.
 ...WHERE Column LIKE  '%' + @Param + '%'

This however only works when the character I search for is not the first character in the string.
How do I need to modify to have the first positionincluded

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-04-08 : 14:02:38
so you mean if @param ='A' it is not working?

Cheers
MIK
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-04-08 : 14:06:39
Works for me
Declare @t table (a varchar(12))
Declare @param varchar(12)
Set @param = 'A'
insert @t values ('A;D;G;F')

select * from @t where a like '%' + @param + '%'

------------
A;D;G;F

(1 row(s) affected)


Show us your actual code.
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-04-09 : 16:50:18
Maybe the search value has the delimited included, which can be a safer way to search.

Try this:

WHERE ';' + Column + ';' LIKE '%' + @Param + '%'

Go to Top of Page
   

- Advertisement -