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)
 How to check if string is inside a string

Author  Topic 

mtlmonk
Starting Member

6 Posts

Posted - 2009-09-23 : 16:07:03
Hello,

In a stored procedure, how can you check that a string is inside another?

I'm not doing this through a query but in the code of the stored procedure.

I need to find out if a string variable is present inside another variable.

DECLARE @part AS VARCHAR(10)
DECLARE @wholeword AS VARCHAR(10)

if "@part is inside of @wholeword"
print 'is inside'
else
print 'is not inside'

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-23 : 16:40:25
if charindex(@part, @wholeword) > 0

Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-24 : 02:30:51
or

if @wholeword like '%'+@part'%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -