We Count HowMany Words Present in This String Through Function in Sql Server
Then Use This Code
Then Use This Code
CREATE FUNCTION fnCountOccurences
(@ShortString VARCHAR(100),
@LongString VARCHAR(8000))
RETURNS INT
AS
BEGIN
DECLARE @Text VARCHAR(8000),
@Frequency INT
SET @Text = @LongString
SET @Text = REPLACE(@Text,@ShortString,'')
SET @Frequency = (len(rtrim(@LongString)) - len(rtrim(@Text)))
/ len(rtrim(@ShortString))
RETURN (@Frequency)
END
We Get OutPut:-
SELECT[dbo].[fnCountOccurences](',','a,b,c,c,')
Execute
OutPut- 4
(@ShortString VARCHAR(100),
@LongString VARCHAR(8000))
RETURNS INT
AS
BEGIN
DECLARE @Text VARCHAR(8000),
@Frequency INT
SET @Text = @LongString
SET @Text = REPLACE(@Text,@ShortString,'')
SET @Frequency = (len(rtrim(@LongString)) - len(rtrim(@Text)))
/ len(rtrim(@ShortString))
RETURN (@Frequency)
END
We Get OutPut:-
SELECT[dbo].[fnCountOccurences](',','a,b,c,c,')
Execute
OutPut- 4
0 comments :
Post a Comment