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 2005 Forums
 Transact-SQL (2005)
 Help me..

Author  Topic 

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-06-26 : 07:06:12
Hello

How 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.

Thanks
Ganesh

Solutions 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
Go to Top of Page

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'
else
print 'string does not exists'[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -