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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 find character in string
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HenryFulmer
Posting Yak Master

USA
110 Posts

Posted - 04/08/2013 :  13:27:14  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/08/2013 :  14:02:38  Show Profile  Reply with Quote
so you mean if @param ='A' it is not working?

Cheers
MIK
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 04/08/2013 :  14:06:39  Show Profile  Visit russell's Homepage  Reply with Quote
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

USA
550 Posts

Posted - 04/09/2013 :  16:50:18  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000