
/****** Object:  UserDefinedFunction [dbo].[ForIDOfPAYAInFormdata]    Script Date: 21/08/2021 05:53:15 ب.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Azimi
-- Create date: 1396/05/05
-- Description:	
-- =============================================
CREATE FUNCTION [dbo].[ForIDOfPAYAInFormdata] 
(
	@FormData nvarchar(1000)
)
RETURNS bigint
AS
BEGIN
	DECLARE @Result bigint

	DECLARE @Index as integer
	SET @Index = 1
	while @Index < 10 and CHARINDEX(';',@FormData)>0
	begin
	--PAYA2;2,22,57,0;3,42,277,0;02/07/2015;12000000;
	--PAYA2;17,88,0,0;1,1,0,0;04/09/2017;100000000;;0;0;1;0
	--PAYA2;17,73,0,0;17,73,0,0;04/09/2017;100000000;;0;0;1;0
		--print @FormData
		set @FormData = Substring(@FormData,CHARINDEX(';',@FormData)+1, 1000)
		set @Index = @Index+1
	end
	SELECT @Result=1
	if @Index >= 10
		if CHARINDEX(';',@FormData)>1
			SELECT @Result =CONVERT(bigint, LEFT(@FormData,CHARINDEX(';',@FormData)-1) )
		else
			SELECT @Result =CONVERT(bigint,  @FormData)

	RETURN @Result

END