Wednesday, September 23, 2009

Checking weather a string is within a string

The following query checks weather a string in within another string or not.


DECLARE @part AS VARCHAR(50)
DECLARE @wholeword AS VARCHAR(50)
set @part='to'         --The string you want to search
set @wholeword='I need to find'--The string you want to check in
if charindex(@part, @wholeword) > 0
print 'is inside'
else
print 'is not inside'

Simple n Cool ha...!

No comments:

Post a Comment