Upper_Bound 

Posted by Philip Leitch Thursday, June 04, 2009 8:57:56 PM
IF EXISTS (SELECT 'x' FROM   sysobjects WHERE  name = 'Upper_Bound')
 DROP FUNCTION Upper_Bound
GO
CREATE FUNCTION Upper_Bound
 (@String as varchar(8000),
 @Delimiter as varchar(8000))
RETURNS int
AS
BEGIN
/*
Author: Philip Leitch
Date: 2001
Purpose: Finds the last entry in a string based on a delimiter element.  This is normally used with the split function to iterate through all entries.
Copyright: Philip Leitch 2001
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
*/
Declare @FoundIndex as int
declare @Length as int
declare @ReturnUBound as int
declare @RemainingString as varchar(8000)

set @FoundIndex = 0
set @ReturnUBound = 0
set @String = ltrim(rtrim(@string))
set @RemainingString = @String
set @FoundIndex = CHARINDEX (@Delimiter, @RemainingString )
while @FoundIndex <> 0
 begin
 set @ReturnUBound = @ReturnUBound + 1
 set @RemainingString = right(@RemainingString, len(@RemainingString) - @FoundIndex)

 set @FoundIndex = CHARINDEX (@Delimiter, @RemainingString )
 end
 RETURN @ReturnUBound
End
GO
-- =============================================
-- Example to execute function
-- =============================================
SELECT dbo.Upper_Bound('Hello, this is a test, to see if the split works, which I am sure it does, and if it does you will see a message saying, this function is working normally, okay?', ', ')
 


Copyright 2009 Philip Leitch

<a href="http://www.megameds.net/">Levitra</a> vgwc <a href="http://www.medicsearchonline.com/">lev

Sunday, May 01, 2011 7:50:01 PM A550RGY

<a href="http://www.goodmedstoday.com/">online accutane</a> =-D <a href="http://www.medicakey.com/"

Friday, April 29, 2011 12:47:42 PM schonr

<a href="http://www.insursafeco.com/">insurance auto</a> :-[ <a href="http://www.easyinsurs.com/">c

Wednesday, April 27, 2011 6:43:39 AM zchewie

aGELlM <a href="http://lkuoyhkavawo.com/">lkuoyhkavawo</a>, [url=http://czmqucxlrrib.com/]czmqucxlr

Saturday, April 02, 2011 1:08:51 AM jbqngofwvqw
aGELlM lkuoyhkavawo, [url=http://czmqucxlrrib.com/]czmqucxlrrib[/url], [link=http://mjqipgrawyrh.com/]mjqipgrawyrh[/link], http://nfcgubpfrxks.com/