/****** Object:  UserDefinedFunction [dbo].[ConcatAcc]    Script Date: 10/8/2025 01:53:30 ب.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

  
CREATE FUNCTION [dbo].[ConcatAccRev]
(
	@Separator as nvarchar(1000),
	@Total as nvarchar(1000)=NULL,
	@Control as nvarchar(1000)=NULL,
	@Detail1 as nvarchar(1000)=NULL,
	@Detail2 as nvarchar(1000)=NULL
) RETURNS NVarCHAR(1000)
AS
BEGIN
	if ISNULL(@Total,'X')='X' or ISNULL(@Separator,'X')='X' or @Total=''
		return ''
	if ISNULL(@Control,'X')='X' or @Control=''
		return RTRIM(@Total)
	if ISNULL(@Detail1,'X')='X' or @Detail1=''
		return RTRIM(@Control)+@Separator+RTRIM(@Total)
	if ISNULL(@Detail2,'X')='X' or @Detail2=''
		return RTRIM(@Detail1)+@Separator+RTRIM(@Control)+@Separator+RTRIM(@Total)
	return RTRIM(@Detail2)+@Separator+RTRIM(@Detail1)+@Separator+RTRIM(@Control)+@Separator+RTRIM(@Total)
END