IF EXISTS(SELECT * FROM SYS.PROCEDURES WHERE NAME='PROC_ProductionSchedule')
	DROP  PROCEDURE  dbo.PROC_ProductionSchedule;
GO
	
CREATE PROCEDURE PROC_ProductionSchedule
	@TableName varchar(100)
	,@STARTDATE date
	,@ENDDATE date
	,@LCID int
	,@SeqFld varchar(200)
	,@year int
	,@month int
	,@HasId int output
AS 
BEGIN
	set @HasId = 0

	IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[T_PLAN_PLANPLMRPT]') AND type IN ('U')) 
		BEGIN
			EXEC PROC_INQUIRE_PLANPLMRPT @TableName,@LCID,@SeqFld,@year,@month, @HasId
		END

	IF @HasId = 0
		BEGIN
			EXEC PROC_INQUIRPLMTMPRTP @TableName,@STARTDATE,@ENDDATE,@LCID,@SeqFld
		END
END