/****** Object:  UserDefinedFunction [dbo].[ForIDOfCashInFormdata]    Script Date: 30/06/2021 09:48:33 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Azimi
-- Create date: 1396/05/05
-- Description:	
-- =============================================
ALTER FUNCTION [dbo].[ForIDOfCashInFormdata] 
(
	@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
	--Cash2;2,22,57,0;3,42,277,0;02/07/2015;12000000;
	--Cash2;17,88,0,0;1,1,0,0;04/09/2017;100000000;;0;0;1;0
	--Cash2;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