
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_REQLIMIT' AND KSQL_COL_NAME IN ('FVALITERM'))
 ALTER TABLE T_TM_REQLIMIT ADD (FVALITERM NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_REQLIMIT' AND KSQL_COL_NAME IN ('FSETTERM'))
 ALTER TABLE T_TM_REQLIMIT ADD (FSETTERM NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TM_REQLIMIT_ENTRY')
 CREATE TABLE T_TM_REQLIMIT_ENTRY (
    FSEQ INT DEFAULT 0 NOT NULL,
    FENTRYID BIGINT DEFAULT 0 NOT NULL,
    FID BIGINT DEFAULT 0 NOT NULL,
    FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
    FLIMITAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FUSEAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FREMAINAMT DECIMAL(23,10) DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TM_REQLIMIT_USE')
 CREATE TABLE T_TM_REQLIMIT_USE (
    FID BIGINT DEFAULT 0 NOT NULL,
    FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
    FBILLSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FCREATORID BIGINT DEFAULT 0 NOT NULL,
    FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
    FAUDITORID BIGINT DEFAULT 0 NOT NULL,
    FAUDITDATE DATETIME,
    FMODIFYTIME DATETIME,
    FCREATETIME DATETIME,
    FORG BIGINT DEFAULT 0 NOT NULL,
    FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
    FLIMITAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FUSEAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FREMAINAMT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TM_REQLIMIT_USE_ENTRY')
 CREATE TABLE T_TM_REQLIMIT_USE_ENTRY (
    FID BIGINT DEFAULT 0 NOT NULL,
    FENTRYID BIGINT DEFAULT 0 NOT NULL,
    FSEQ INT DEFAULT 0 NOT NULL,
    FBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FPRODUCTTYPEID BIGINT DEFAULT 0 NOT NULL,
    FBILLUSEAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FBILLID BIGINT DEFAULT 0 NOT NULL,
    FBILLTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL
);



