/**Begin D:\k3Cloud\PDM_UPGRADE\PDM1\MDS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FFIELDTRANS') 
 ALTER TABLE T_MDS_WRTFF ADD (FFIELDTRANS BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_WRITEOFFREC') 
 CREATE TABLE T_MDS_WRITEOFFREC (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) 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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FMATERIEL BIGINT DEFAULT 0 NOT NULL,
FSALEORDER BIGINT DEFAULT 0 NOT NULL,
FRPD DATETIME,
FEPD DATETIME,
FDELEVERYDATE DATETIME,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSALEORDEROUTID BIGINT DEFAULT 0 NOT NULL,
FBILLTYPE BIGINT DEFAULT 0 NOT NULL,
FORDERSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSALEORDERUNIT BIGINT DEFAULT 0 NOT NULL,
FSALEOUTENTRYID BIGINT DEFAULT 0 NOT NULL,
FSALEOUTLINE BIGINT DEFAULT 0 NOT NULL,
FORDERNO BIGINT DEFAULT 0 NOT NULL,
FVERSIONID BIGINT DEFAULT 0 NOT NULL,
FTRANSFERID BIGINT DEFAULT 0 NOT NULL,
FRECORDDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_WRITEOFFREC_L') 
 CREATE TABLE T_MDS_WRITEOFFREC_L (
FPKID NVARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRITEOFFREC' AND KSQL_COL_NAME ='FBILLSTATUS') 
 ALTER TABLE T_MDS_WRITEOFFREC ADD (FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL);


/**End D:\k3Cloud\PDM_UPGRADE\PDM1\MDS_table.sql **/
