/** 维度匹配规则分组表 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DIMMATERULEGROUP') 
CREATE TABLE T_EB_DIMMATERULEGROUP (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FBILL           		BIGINT               NOT NULL DEFAULT 0,
   FAPPLICATION         BIGINT        		 NOT NULL DEFAULT 0,
   FSTATUS          	CHAR(1)        		 NOT NULL DEFAULT '1',
   FISONLYCHECK         CHAR(1)              NOT NULL DEFAULT '0',
   FGROUPNAME      		NVARCHAR(50)         NOT NULL DEFAULT ' ',
   FDISCRIPTION         NVARCHAR(500)        NOT NULL DEFAULT ' ',
   FNUMBER           	NVARCHAR(500)        NOT NULL DEFAULT ' ',
   FMODIFIER			BIGINT				 NOT NULL DEFAULT 0,
   FMODIFYDATE			DATETIME
);
EXEC P_ALTERPK 'PK_T_EB_DIMMATERULEGROUP', 'T_EB_DIMMATERULEGROUP', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_DIMMATERULEGROUP_BILL') CREATE INDEX IDX_T_EB_DIMMATERULEGROUP_BILL ON T_EB_DIMMATERULEGROUP (FBILL,FSTATUS);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_DIMMATERULEGROUP_NUMBER') CREATE INDEX IDX_T_EB_DIMMATERULEGROUP_NUMBER ON T_EB_DIMMATERULEGROUP (FSTATUS);
 
/** 维度匹配规则分组多语言表 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DIMMATERULEGROUP_L') 
CREATE TABLE T_EB_DIMMATERULEGROUP_L (
   FPKID                NVARCHAR(30)         NOT NULL DEFAULT ' ',
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FLOCALEID            NVARCHAR(10)         NOT NULL DEFAULT ' ',
   FGROUPNAME           NVARCHAR(500)        NOT NULL DEFAULT ' ',
   FDISCRIPTION         NVARCHAR(500)        NOT NULL DEFAULT ' '
);
EXEC P_ALTERPK 'PK_T_EB_DIMMATERULEGROUP_L', 'T_EB_DIMMATERULEGROUP_L', 'FPKID', '1';


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FID')
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FID BIGINT NOT NULL DEFAULT 0);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FMODELID')
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FMODELID BIGINT NOT NULL DEFAULT 0);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FCONTROLDIMENSION')
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FCONTROLDIMENSION NVARCHAR(500) NOT NULL DEFAULT ' ');
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FISONLYCONTROLSUIT')
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FISONLYCONTROLSUIT CHAR(1) NOT NULL DEFAULT '0');
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL_L' AND KSQL_COL_NAME ='FTITLE') 
 ALTER TABLE T_EB_DIMMATERULEBILL_L ADD (FTITLE NVARCHAR(500) NOT NULL DEFAULT 0);

delete from t_eb_dimmaterulebill_l where ftitle ='0';