USE [AJK]
GO

/****** Object:  View [dbo].[view_custport_flow]    Script Date: 20/07/2018 9:59:53 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO





-- created by Pribadi Pamungkas. 2018-07-06
ALTER VIEW [dbo].[view_custport_flow]
AS
	SELECT TOP 100 PERCENT
		mf.flow_id, mf.flow_code, mf.description AS flow_description, mf.transaction_type_code, 
		mfs.flow_stage_id, mfs.flow_stage_code, mfs.description AS flow_stage_description, mfs.sequence_no, 
		mfa.flow_action_id, mfa.flow_action_code, mfa.description AS flow_action_description, mfa.is_external_process, mfa.next_flow_stage, mfa.next_status_code, mfa.is_need_reason, mfa.reason_type_code, mfa.is_reference_no,
		next_stage.next_flow_stage_description
	FROM
		custport_m_flow AS mf INNER JOIN
		custport_m_flow_stage AS mfs ON mf.flow_code = mfs.flow_code INNER JOIN
		custport_m_flow_action AS mfa ON mfs.flow_stage_code = mfa.flow_stage_code LEFT JOIN
		(
			SELECT
				flow_stage_id, flow_stage_code, flow_code, description AS next_flow_stage_description
			FROM
				custport_m_flow_stage
			WHERE
				is_active = 1
		) AS next_stage ON mfa.next_flow_stage = next_stage.flow_stage_code
	WHERE
		mf.is_active = 1
		AND mfs.is_active = 1
		AND mfa.is_active = 1
	ORDER BY
		mfs.sequence_no



GO


