USE [db_edits]
GO

/****** Object:  UserDefinedFunction [dbo].[get_is_follow_up_audit]    Script Date: 03/02/2018 14:42:38 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[get_is_follow_up_audit]
(
	@pi_transaction_id BIGINT
)
RETURNS VARCHAR(50)
AS
BEGIN

	DECLARE @is_follow_up VARCHAR(50);

	SET @is_follow_up = (
		SELECT TOP 1
			s.is_follow_up
		FROM t_audit_history h
		JOIN m_status_audit s ON h.id_status_audit = s.id_status_audit
		WHERE h.id_transaction = @pi_transaction_id
		ORDER BY h.created_date DESC
	);

	RETURN @is_follow_up;

END

GO


