--drop table "VIRTAPORTAL"."CPO_CHARGES";
CREATE COLUMN TABLE "VIRTAPORTAL"."CPO_CHARGES"(
	"CDRID" NVARCHAR(50) NOT NULL,
	"UUID" NVARCHAR(50),
	"STATIONUUID" NVARCHAR(50),
	"EMPSELLERID" BIGINT CS_FIXED,
	"STARTTIME" NVARCHAR(50),
	"STOPTIME" NVARCHAR(50),
	"DURATION" INTEGER CS_INT,
	"WATTHOUR" INTEGER CS_INT,
	"AMOUNT" INTEGER CS_INT,
	"CURRENCY" NVARCHAR(3),
	"METHOD" NVARCHAR(50),
	"CREATED" NVARCHAR(50),
	"RFID" NVARCHAR(50),
	"STATION" NCLOB MEMORY THRESHOLD 1000,
	"STATION_ID" NVARCHAR(50),
	"STATION_NAME" NVARCHAR(100),
	"LOCATION_ID" INTEGER CS_INT,
	"LOCATION_ADDRESS" NVARCHAR(100),
	"LOCATION_CITY" NVARCHAR(100),
	"LOCATION_TYPE" NVARCHAR(50),
	"ROAMINGEMPID" NVARCHAR(50),
	"EVCOID" NVARCHAR(100),
	"ORGANIZATIONID" NVARCHAR(50),
	"FULLEVSEID" NVARCHAR(50),
	"EVSEID" NVARCHAR(50),
	"PLUGTYPE" NVARCHAR(50),
	"EMPSHARE" INTEGER CS_INT,
	"SIGNEDMETERVALUEBEGIN" NVARCHAR(50),
	"SIGNEDMETERVALUEEND" NVARCHAR(50),
	"FREECHARGING" NVARCHAR(3),
	"CONNECTORID"  INTEGER CS_INT,
	"METERSTART" INTEGER CS_INT,
	"METERSTOP" INTEGER CS_INT,
	"NOTES"  NVARCHAR(500),
	"MILEAGE"  INTEGER CS_INT,
	"JSONRAW" NCLOB MEMORY THRESHOLD 1000,
	"CREATE_TS" LONGDATE CS_LONGDATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"UPDATE_TS" LONGDATE CS_LONGDATE NOT NULL,
	"STATUS" VARCHAR(1) DEFAULT 'N',
	"BILLING" VARCHAR(1) DEFAULT 'Y',
	PRIMARY KEY (
		"CDRID"
	)
)
UNLOAD PRIORITY 5 AUTO MERGE;


ALTER TABLE "VIRTAPORTAL"."CPO_CHARGES" ADD (
"CREATE_USER" NVARCHAR(50) DEFAULT CURRENT_USER NOT NULL
);


ALTER TABLE "VIRTAPORTAL"."CPO_CHARGES" ADD (
"UPDATE_USER" NVARCHAR(50) DEFAULT CURRENT_USER NOT NULL
);

ALTER TABLE "VIRTAPORTAL"."CPO_CHARGES" ALTER (
"FULLEVSEID_REDUCED" NVARCHAR(5000) AS NULLIF("substr_regex"("FULLEVSEID", '^(.*)(\\*\\d)$', 1, 1, 1, ''), "FULLEVSEID")
);
