IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.AUDIT_upd_Reservations') AND OBJECTPROPERTY(id, N'IsTrigger') = 1) DROP TRIGGER dbo.AUDIT_upd_Reservations 
GO
CREATE TRIGGER [dbo].[AUDIT_upd_Reservations]
ON [dbo].[Reservations] FOR UPDATE NOT FOR REPLICATION AS
BEGIN
	

	DECLARE 
		@IDENTITY_SAVE			varchar(50),
		@AUDIT_LOG_TRANSACTION_ID	Int,
		@PRIM_KEY			nvarchar(4000),
		@Inserted	    		bit,
 		@ROWS_COUNT				int,
		@FK_UserIdNumber INT,
		@FK_CashBox INT,
		@ProgramPart SMALLINT,
		@TerminalName VARCHAR(50),
		@SystemDateStr VARCHAR(8),
		@SystemDateTime DATETIME

	SET NOCOUNT ON

	Select @ROWS_COUNT=count(*) from inserted
	SET @IDENTITY_SAVE = CAST(IsNull(@@IDENTITY,1) AS varchar(50))

    SELECT TOP 1 @FK_UserIdNumber = FK_UserIdNumber,
	@FK_CashBox = FK_CashBox,
	@ProgramPart = ProgramPart,
	@TerminalName = TerminalName
	FROM PersonnelLogInfo WITH (NOLOCK)
	WHERE spid = @@spid 
	ORDER BY CreateDate DESC

	IF ISNULL(@FK_UserIdNumber, 0) = 0
	  SET @FK_UserIdNumber = 1
	IF ISNULL(@FK_CashBox, -1) <= 0
	  SET @FK_CashBox = -1
	IF ISNULL(@ProgramPart, -1) <= 0
	  SET @ProgramPart = 14 -- ppUnknown from SystemAll
	IF ISNULL(@TerminalName, '') = ''
	  SET @TerminalName = 'Unknown'

    SELECT @SystemDateStr = SystemDate FROM System WITH (NOLOCK) WHERE Number = 1
    SET @SystemDateTime = CONVERT(DATETIME, @SystemDateStr + ' ' + CONVERT(CHAR(8), CURRENT_TIMESTAMP, 108))

	INSERT INTO dbo.AUDIT_LOG_TRANSACTIONS
	(
		TABLE_NAME,
		TABLE_SCHEMA,
		AUDIT_ACTION_ID,
		HOST_NAME,
		APP_NAME,
		MODIFIED_BY,
		MODIFIED_DATE,
		AFFECTED_ROWS,
		FK_UserIdNumber,
		FK_CashBox,
		ProgramPart,
		TerminalName,
		RealDateTime
	)
	values(
		'Reservations',
		'dbo',
		1,	--	ACTION ID For UPDATE
		CASE 
		  WHEN LEN(HOST_NAME()) < 1 THEN ' '
		  ELSE HOST_NAME()
		END,
		CASE 
		  WHEN LEN(APP_NAME()) < 1 THEN ' '
		  ELSE APP_NAME()
		END,
		SUSER_SNAME(),
		@SystemDateTime,
		@ROWS_COUNT,
		@FK_UserIdNumber,
		@FK_CashBox,
		@ProgramPart,
		@TerminalName,
		GETDATE()
	)	
	
	Set @AUDIT_LOG_TRANSACTION_ID = SCOPE_IDENTITY()
	
	SET @Inserted = 0
	
	If UPDATE([Status])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Status',
			CONVERT(nvarchar(4000), OLD.[Status], 0),
			CONVERT(nvarchar(4000), NEW.[Status], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Status] <>
					OLD.[Status]
				) Or
			
				(
					NEW.[Status] Is Null And
					OLD.[Status] Is Not Null
				) Or
				(
					NEW.[Status] Is Not Null And
					OLD.[Status] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ArrivalDate])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ArrivalDate',
			CONVERT(nvarchar(4000), OLD.[ArrivalDate], 0),
			CONVERT(nvarchar(4000), NEW.[ArrivalDate], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ArrivalDate] <>
					OLD.[ArrivalDate]
				) Or
			
				(
					NEW.[ArrivalDate] Is Null And
					OLD.[ArrivalDate] Is Not Null
				) Or
				(
					NEW.[ArrivalDate] Is Not Null And
					OLD.[ArrivalDate] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ArrivalTime])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ArrivalTime',
			CONVERT(nvarchar(4000), OLD.[ArrivalTime], 0),
			CONVERT(nvarchar(4000), NEW.[ArrivalTime], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ArrivalTime] <>
					OLD.[ArrivalTime]
				) Or
			
				(
					NEW.[ArrivalTime] Is Null And
					OLD.[ArrivalTime] Is Not Null
				) Or
				(
					NEW.[ArrivalTime] Is Not Null And
					OLD.[ArrivalTime] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([DepartureDate])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'DepartureDate',
			CONVERT(nvarchar(4000), OLD.[DepartureDate], 0),
			CONVERT(nvarchar(4000), NEW.[DepartureDate], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[DepartureDate] <>
					OLD.[DepartureDate]
				) Or
			
				(
					NEW.[DepartureDate] Is Null And
					OLD.[DepartureDate] Is Not Null
				) Or
				(
					NEW.[DepartureDate] Is Not Null And
					OLD.[DepartureDate] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([DepartureTime])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'DepartureTime',
			CONVERT(nvarchar(4000), OLD.[DepartureTime], 0),
			CONVERT(nvarchar(4000), NEW.[DepartureTime], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[DepartureTime] <>
					OLD.[DepartureTime]
				) Or
			
				(
					NEW.[DepartureTime] Is Null And
					OLD.[DepartureTime] Is Not Null
				) Or
				(
					NEW.[DepartureTime] Is Not Null And
					OLD.[DepartureTime] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ProductNumber])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ProductNumber',
			CONVERT(nvarchar(4000), OLD.[ProductNumber], 0),
			CONVERT(nvarchar(4000), NEW.[ProductNumber], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ProductNumber] <>
					OLD.[ProductNumber]
				) Or
			
				(
					NEW.[ProductNumber] Is Null And
					OLD.[ProductNumber] Is Not Null
				) Or
				(
					NEW.[ProductNumber] Is Not Null And
					OLD.[ProductNumber] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ProductNumber2])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ProductNumber2',
			CONVERT(nvarchar(4000), OLD.[ProductNumber2], 0),
			CONVERT(nvarchar(4000), NEW.[ProductNumber2], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ProductNumber2] <>
					OLD.[ProductNumber2]
				) Or
			
				(
					NEW.[ProductNumber2] Is Null And
					OLD.[ProductNumber2] Is Not Null
				) Or
				(
					NEW.[ProductNumber2] Is Not Null And
					OLD.[ProductNumber2] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ProductNumber3])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ProductNumber3',
			CONVERT(nvarchar(4000), OLD.[ProductNumber3], 0),
			CONVERT(nvarchar(4000), NEW.[ProductNumber3], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ProductNumber3] <>
					OLD.[ProductNumber3]
				) Or
			
				(
					NEW.[ProductNumber3] Is Null And
					OLD.[ProductNumber3] Is Not Null
				) Or
				(
					NEW.[ProductNumber3] Is Not Null And
					OLD.[ProductNumber3] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([ProductNumber4])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'ProductNumber4',
			CONVERT(nvarchar(4000), OLD.[ProductNumber4], 0),
			CONVERT(nvarchar(4000), NEW.[ProductNumber4], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[ProductNumber4] <>
					OLD.[ProductNumber4]
				) Or
			
				(
					NEW.[ProductNumber4] Is Null And
					OLD.[ProductNumber4] Is Not Null
				) Or
				(
					NEW.[ProductNumber4] Is Not Null And
					OLD.[ProductNumber4] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([Price])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Price',
			CONVERT(nvarchar(4000), OLD.[Price], 2),
			CONVERT(nvarchar(4000), NEW.[Price], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Price] <>
					OLD.[Price]
				) Or
			
				(
					NEW.[Price] Is Null And
					OLD.[Price] Is Not Null
				) Or
				(
					NEW.[Price] Is Not Null And
					OLD.[Price] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([TotalPrice])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'TotalPrice',
			CONVERT(nvarchar(4000), OLD.[TotalPrice], 2),
			CONVERT(nvarchar(4000), NEW.[TotalPrice], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[TotalPrice] <>
					OLD.[TotalPrice]
				) Or
			
				(
					NEW.[TotalPrice] Is Null And
					OLD.[TotalPrice] Is Not Null
				) Or
				(
					NEW.[TotalPrice] Is Not Null And
					OLD.[TotalPrice] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([PriceOverwritten])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'PriceOverwritten',
			CONVERT(nvarchar(4000), OLD.[PriceOverwritten], 0),
			CONVERT(nvarchar(4000), NEW.[PriceOverwritten], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[PriceOverwritten] <>
					OLD.[PriceOverwritten]
				) Or
			
				(
					NEW.[PriceOverwritten] Is Null And
					OLD.[PriceOverwritten] Is Not Null
				) Or
				(
					NEW.[PriceOverwritten] Is Not Null And
					OLD.[PriceOverwritten] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([PriceOverwritten2])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'PriceOverwritten2',
			CONVERT(nvarchar(4000), OLD.[PriceOverwritten2], 0),
			CONVERT(nvarchar(4000), NEW.[PriceOverwritten2], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[PriceOverwritten2] <>
					OLD.[PriceOverwritten2]
				) Or
			
				(
					NEW.[PriceOverwritten2] Is Null And
					OLD.[PriceOverwritten2] Is Not Null
				) Or
				(
					NEW.[PriceOverwritten2] Is Not Null And
					OLD.[PriceOverwritten2] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([PriceOverwritten3])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'PriceOverwritten3',
			CONVERT(nvarchar(4000), OLD.[PriceOverwritten3], 0),
			CONVERT(nvarchar(4000), NEW.[PriceOverwritten3], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[PriceOverwritten3] <>
					OLD.[PriceOverwritten3]
				) Or
			
				(
					NEW.[PriceOverwritten3] Is Null And
					OLD.[PriceOverwritten3] Is Not Null
				) Or
				(
					NEW.[PriceOverwritten3] Is Not Null And
					OLD.[PriceOverwritten3] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([PriceOverwritten4])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'PriceOverwritten4',
			CONVERT(nvarchar(4000), OLD.[PriceOverwritten4], 0),
			CONVERT(nvarchar(4000), NEW.[PriceOverwritten4], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[PriceOverwritten4] <>
					OLD.[PriceOverwritten4]
				) Or
			
				(
					NEW.[PriceOverwritten4] Is Null And
					OLD.[PriceOverwritten4] Is Not Null
				) Or
				(
					NEW.[PriceOverwritten4] Is Not Null And
					OLD.[PriceOverwritten4] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([FirstPrice1])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'FirstPrice1',
			CONVERT(nvarchar(4000), OLD.[FirstPrice1], 2),
			CONVERT(nvarchar(4000), NEW.[FirstPrice1], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[FirstPrice1] <>
					OLD.[FirstPrice1]
				) Or
			
				(
					NEW.[FirstPrice1] Is Null And
					OLD.[FirstPrice1] Is Not Null
				) Or
				(
					NEW.[FirstPrice1] Is Not Null And
					OLD.[FirstPrice1] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([FirstPrice2])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'FirstPrice2',
			CONVERT(nvarchar(4000), OLD.[FirstPrice2], 2),
			CONVERT(nvarchar(4000), NEW.[FirstPrice2], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[FirstPrice2] <>
					OLD.[FirstPrice2]
				) Or
			
				(
					NEW.[FirstPrice2] Is Null And
					OLD.[FirstPrice2] Is Not Null
				) Or
				(
					NEW.[FirstPrice2] Is Not Null And
					OLD.[FirstPrice2] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([FirstPrice3])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'FirstPrice3',
			CONVERT(nvarchar(4000), OLD.[FirstPrice3], 2),
			CONVERT(nvarchar(4000), NEW.[FirstPrice3], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[FirstPrice3] <>
					OLD.[FirstPrice3]
				) Or
			
				(
					NEW.[FirstPrice3] Is Null And
					OLD.[FirstPrice3] Is Not Null
				) Or
				(
					NEW.[FirstPrice3] Is Not Null And
					OLD.[FirstPrice3] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([FirstPrice4])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'FirstPrice4',
			CONVERT(nvarchar(4000), OLD.[FirstPrice4], 2),
			CONVERT(nvarchar(4000), NEW.[FirstPrice4], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[FirstPrice4] <>
					OLD.[FirstPrice4]
				) Or
			
				(
					NEW.[FirstPrice4] Is Null And
					OLD.[FirstPrice4] Is Not Null
				) Or
				(
					NEW.[FirstPrice4] Is Not Null And
					OLD.[FirstPrice4] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([TotalPrice1])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'TotalPrice1',
			CONVERT(nvarchar(4000), OLD.[TotalPrice1], 2),
			CONVERT(nvarchar(4000), NEW.[TotalPrice1], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[TotalPrice1] <>
					OLD.[TotalPrice1]
				) Or
			
				(
					NEW.[TotalPrice1] Is Null And
					OLD.[TotalPrice1] Is Not Null
				) Or
				(
					NEW.[TotalPrice1] Is Not Null And
					OLD.[TotalPrice1] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([TotalPrice2])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'TotalPrice2',
			CONVERT(nvarchar(4000), OLD.[TotalPrice2], 2),
			CONVERT(nvarchar(4000), NEW.[TotalPrice2], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[TotalPrice2] <>
					OLD.[TotalPrice2]
				) Or
			
				(
					NEW.[TotalPrice2] Is Null And
					OLD.[TotalPrice2] Is Not Null
				) Or
				(
					NEW.[TotalPrice2] Is Not Null And
					OLD.[TotalPrice2] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([TotalPrice3])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'TotalPrice3',
			CONVERT(nvarchar(4000), OLD.[TotalPrice3], 2),
			CONVERT(nvarchar(4000), NEW.[TotalPrice3], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[TotalPrice3] <>
					OLD.[TotalPrice3]
				) Or
			
				(
					NEW.[TotalPrice3] Is Null And
					OLD.[TotalPrice3] Is Not Null
				) Or
				(
					NEW.[TotalPrice3] Is Not Null And
					OLD.[TotalPrice3] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([TotalPrice4])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'TotalPrice4',
			CONVERT(nvarchar(4000), OLD.[TotalPrice4], 2),
			CONVERT(nvarchar(4000), NEW.[TotalPrice4], 2),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[TotalPrice4] <>
					OLD.[TotalPrice4]
				) Or
			
				(
					NEW.[TotalPrice4] Is Null And
					OLD.[TotalPrice4] Is Not Null
				) Or
				(
					NEW.[TotalPrice4] Is Not Null And
					OLD.[TotalPrice4] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([Currency])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Currency',
			CONVERT(nvarchar(4000), OLD.[Currency], 0),
			CONVERT(nvarchar(4000), NEW.[Currency], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Currency] <>
					OLD.[Currency]
				) Or
			
				(
					NEW.[Currency] Is Null And
					OLD.[Currency] Is Not Null
				) Or
				(
					NEW.[Currency] Is Not Null And
					OLD.[Currency] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([Day2])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Day2',
			CONVERT(nvarchar(4000), OLD.[Day2], 0),
			CONVERT(nvarchar(4000), NEW.[Day2], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Day2] <>
					OLD.[Day2]
				) Or
			
				(
					NEW.[Day2] Is Null And
					OLD.[Day2] Is Not Null
				) Or
				(
					NEW.[Day2] Is Not Null And
					OLD.[Day2] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([Day3])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Day3',
			CONVERT(nvarchar(4000), OLD.[Day3], 0),
			CONVERT(nvarchar(4000), NEW.[Day3], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Day3] <>
					OLD.[Day3]
				) Or
			
				(
					NEW.[Day3] Is Null And
					OLD.[Day3] Is Not Null
				) Or
				(
					NEW.[Day3] Is Not Null And
					OLD.[Day3] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	If UPDATE([Day4])
	BEGIN
    
		INSERT
		INTO dbo.AUDIT_LOG_DATA
		(
			AUDIT_LOG_TRANSACTION_ID,
			PRIMARY_KEY_DATA,
			COL_NAME,
			OLD_VALUE_LONG,
			NEW_VALUE_LONG,
			DATA_TYPE
			, KEY1, KEY2
		)
		SELECT
			@AUDIT_LOG_TRANSACTION_ID,
		    convert(nvarchar(1500), IsNull('[ReferenceNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[ReferenceNumber], NEW.[ReferenceNumber]), 0), '[ReferenceNumber] Is Null')+' AND '+IsNull('[GuestNumber]='+CONVERT(nvarchar(4000), IsNull(OLD.[GuestNumber], NEW.[GuestNumber]), 0), '[GuestNumber] Is Null')),
		    'Day4',
			CONVERT(nvarchar(4000), OLD.[Day4], 0),
			CONVERT(nvarchar(4000), NEW.[Day4], 0),
			'A'
			, IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0))), IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[GuestNumber], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)))
			
		FROM deleted OLD Inner Join inserted NEW On 
			(CONVERT(nvarchar(4000), NEW.[ReferenceNumber], 0)=CONVERT(nvarchar(4000), OLD.[ReferenceNumber], 0) or (NEW.[ReferenceNumber] Is Null and OLD.[ReferenceNumber] Is Null)) AND (CONVERT(nvarchar(4000), NEW.[GuestNumber], 0)=CONVERT(nvarchar(4000), OLD.[GuestNumber], 0) or (NEW.[GuestNumber] Is Null and OLD.[GuestNumber] Is Null))
			where (
			
			
				(
					NEW.[Day4] <>
					OLD.[Day4]
				) Or
			
				(
					NEW.[Day4] Is Null And
					OLD.[Day4] Is Not Null
				) Or
				(
					NEW.[Day4] Is Not Null And
					OLD.[Day4] Is Null
				)
				)
        
		SET @Inserted = CASE WHEN @@ROWCOUNT > 0 Then 1 Else @Inserted End
	END
	
	-- Watch
	
	-- Lookup
	
	IF @Inserted = 0
	BEGIN
		DELETE FROM dbo.AUDIT_LOG_TRANSACTIONS WHERE AUDIT_LOG_TRANSACTION_ID = @AUDIT_LOG_TRANSACTION_ID
	END
	-- Restore @@IDENTITY Value  
    DECLARE @maxprec AS varchar(2)
    SET @maxprec=CAST(@@MAX_PRECISION as varchar(2))
    EXEC('SELECT IDENTITY(decimal('+@maxprec+',0),'+@IDENTITY_SAVE+',1) id INTO #tmp')
End
