May 27, 2009 at 9:27 pm
Hi Friends...
I need find the exact string pattern in an String
For Eg:
my Main String is like this
Declare @Str='I am going to have Asset table
and in that table i have AssetId and AssetName as Columns
And this Asset
table is having more Records'
I have to find The NoOf Occurences of Exact Word: Asset
Coul u Please help me in Sorting out this Problem
May 27, 2009 at 9:45 pm
ningaraju.n (5/27/2009)
Hi Friends...I need find the exact string pattern in an String
For Eg:
my Main String is like this
Declare @Str='I am going to have Asset table
and in that table i have AssetId and AssetName as Columns
And this Asset
table is having more Records'
I have to find The NoOf Occurences of Exact Word: Asset
Coul u Please help me in Sorting out this Problem
Please don't think that this is a dumb or stupid question, but based on the sample data above how many occurances of te word "Asset" would this routine return?
May 28, 2009 at 4:28 am
ningaraju.n (5/27/2009)
Hi Friends...I need find the exact string pattern in an String
For Eg:
my Main String is like this
Declare @Str='I am going to have Asset table
and in that table i have AssetId and AssetName as Columns
And this Asset
table is having more Records'
I have to find The NoOf Occurences of Exact Word: Asset
Coul u Please help me in Sorting out this Problem
You should specify more clearly what is an "Exact Word".
I assume you mean that a word is a sequence of letters with exact word you mean that you want to find "Asset" bot not "AssetName".
You can use PATINDEX to find the occurrences, repeating with a loop until there are no more occurrencies, like this:
[font="Courier New"]Declare @Str varchar(1000)
declare @word varchar(1000)
select @str='I am going to have Asset table
and in that table i have AssetId and AssetName as Columns
And this Asset
table is having more Records'
select @word = 'Asset'
declare @n int, @i int
select @n = 0
select @str
select @i = patindex( '%[^A-Z]'+@word+'[^A-Z]%', '-'+@str+'-')
while @i > 0
begin
select @n = @n + 1
select @str = SUBSTRING( @str, @i+LEN(@word), 9999 )
select @i = patindex( '%[^A-Z]'+@word+'[^A-Z]%', '-'+@str+'-')
end
select @n[/font]
ciao
Giacomo
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply