

--  ------------  Generated from [/big2/11.0/Build80_SP24/cxunix/source/CommServer/AppStudioDB/Function/AZ_StringSplitFunction.func] ---------- 


SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON

SET NOCOUNT ON


print '... Creating Function: AZ_StringSplitFunction'
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[AZ_StringSplitFunction]') and (OBJECTPROPERTY(id, N'IsInlineFunction') = 1 OR OBJECTPROPERTY(id, N'IsTableFunction') = 1 OR OBJECTPROPERTY(id, N'IsScalarFunction') = 1))
BEGIN
  drop function [dbo].[AZ_StringSplitFunction]
  delete from GXDBVersions where name = 'AZ_StringSplitFunction' and type = 5
END
GO

CREATE FUNCTION [dbo].[AZ_StringSplitFunction]
	(
		@List  nvarchar(max),
		@Delimiter nchar(1)
	)
	RETURNS @t table (Item nvarchar(max))
	AS
	BEGIN
		SET @List += @Delimiter;
		;WITH a(f,t) AS
			(
				SELECT CAST(1 AS bigint), CHARINDEX(@Delimiter, @List)
				UNION ALL
				SELECT t + 1, CHARINDEX(@Delimiter, @List, t + 1)
				FROM a WHERE CHARINDEX(@Delimiter, @List, t + 1) > 0
			)
			INSERT @t SELECT LTRIM(RTRIM(SUBSTRING(@List, f, t - f))) FROM a OPTION (MAXRECURSION 0);
		RETURN;
	END


GO
declare @retCode integer		-- Now do Error Check
set @retCode = @@error
if (@retCode <> 0)
BEGIN
	set @retCode = @@error;
	print 'RETVAL: 04 Function [AZ_StringSplitFunction]'
END
GO


if NOT EXISTS (SELECT * FROM GXDBVersions WHERE type = 5 AND name = 'AZ_StringSplitFunction' AND revision = '')

  insert into GXDBVersions values(5, 'AZ_StringSplitFunction',  '', 'AZ_StringSplitFunction', '')
GO

declare @retCode integer		-- Now do Error Check
set @retCode = @@error
if (@retCode <> 0)
BEGIN
	set @retCode = @@error;
	print 'RETVAL: 10 Table [GXDBVersions]'
END
GO


SET NOCOUNT OFF
