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.
| Author |
Topic |
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-06-26 : 07:06:12
|
| HelloHow to check whether the String is available in another string.For Ex: Declare @InputString varchar(100)Set @InputString = '[Ganesh Kumar],[Kadamba]'Declare @MyString varchar(100)Set @MyString = '[Ganesh Kumar]'So, '[Ganesh Kumar]' is available in @inputString.How to check the availablity.ThanksGaneshSolutions are easy. Understanding the problem, now, that's the hard part |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-26 : 07:19:30
|
| SELECT CASE WHEN PATINDEX('%'+ @MyString + '%',@InputString )> 0 THEN 'Present' ELSE 'Not Present' END |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-06-26 : 07:21:38
|
| [code]Declare @InputString varchar(100)Set @InputString = '[Ganesh Kumar],[Kadamba]'Declare @MyString varchar(100)Set @MyString = '[Ganesh Kumar]'if @InputString like '%' + replace(replace(@MyString, '[', '/['), ']', '/]') + '%' ESCAPE '/' print 'string exists'elseprint 'string does not exists'[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-06-26 : 07:23:13
|
quote: Originally posted by visakh16 SELECT CASE WHEN PATINDEX('%'+ @MyString + '%',@InputString )> 0 THEN 'Present' ELSE 'Not Present' END
That wouldn't work if:Set @MyString = '[Ganesh Kumarabc]'in fact it won't work if you put any junk characters inside []Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|