
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PMTS_WBS_ORDER')
CREATE TABLE T_PMTS_WBS_ORDER
(
	FID 					    BIGINT 	                   DEFAULT 0         NOT NULL, 		
	FENTRYID        	        BIGINT 	                   DEFAULT 0         NOT NULL,       
	FSEQ           		        INT  	               	   DEFAULT 0         NOT NULL,  
	FORDERTYPE 					NVARCHAR(50)               DEFAULT ' '       NOT NULL,   		
	FORDERNO        	        NVARCHAR(50)               DEFAULT ' '       NOT NULL,      
	FPROCESS           		    NVARCHAR(50)               DEFAULT ' '       NOT NULL,          
	FORDERPRO 		            NVARCHAR(50)               DEFAULT ' '       NOT NULL,       
	FORDERLOCAL 			    NVARCHAR(30)               DEFAULT ' '       NOT NULL,       
	FORDERID 			        NVARCHAR(50)               DEFAULT ' '       NOT NULL   
);

EXEC P_ALTERPK 'PK_PMTS_WBS_ORDER', 'T_PMTS_WBS_ORDER', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PMTS_WBS_ORDER_FS') CREATE INDEX IDX_PMTS_WBS_ORDER_FS ON T_PMTS_WBS_ORDER ( FID ,FSEQ );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMTS_WBS' AND KSQL_COL_NAME ='FDEVICE')
  ALTER TABLE T_PMTS_WBS ADD (FDEVICE BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMTS_WBS' AND KSQL_COL_NAME ='FPACKAGE')
  ALTER TABLE T_PMTS_WBS ADD (FPACKAGE BIGINT DEFAULT 0 NOT NULL );
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMTS_WBS' AND KSQL_COL_NAME ='FRANGE')
  ALTER TABLE T_PMTS_WBS ADD (FRANGE BIGINT DEFAULT 0 NOT NULL );
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMTS_WBS' AND KSQL_COL_NAME ='FPROFESSION')
  ALTER TABLE T_PMTS_WBS ADD (FPROFESSION BIGINT DEFAULT 0 NOT NULL );
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMTS_WBS' AND KSQL_COL_NAME ='FFUNLOCATION')
  ALTER TABLE T_PMTS_WBS ADD (FFUNLOCATION BIGINT DEFAULT 0 NOT NULL );