ignore first two characters on a column while importing csv to mysql -


i trying import csv file mysql table, need remove first 2 characters on particular column before importing mysql. statment :

 string strloaddata = "load data local  infile 'e:/park/export.csv' table tickets  fields  terminated ',' enclosed '\"'  lines terminated '\n' ignore 1 lines (siteid,datetime,serial,deviceid,agentaid,vehicleregistration,carpark,spacenumber,gpsaddress,vehicletype,vehiclemake,vehiclemodel,vehiclecolour,issuereasoncode,issuereason,noticelocation,points,notes)"; 

column issuereasoncode' has data 'lu12' , need remove first 2 characters should have integers on , not alpha numeric . need remove 'lu' column.

is possible write on left(issuereasoncode +' '2). column varchar(45) , cant changed because of large data on it.

thanks

load data infile has ability perform function on data each column read in (q.v. here). in case, if wanted remove first 2 characters issuereasoncode column, use:

right(issuereasoncode, char_length(issuereasoncode) - 2) 

to remove first 2 characters. specify such column mappings @ end of load data statement using set. statement should following:

load data local infile 'e:/park/export.csv' table tickets fields terminated ',' enclosed '\"' lines terminated '\n' ignore 1 lines (siteid, datetime, serial, deviceid, agentaid, vehicleregistration, carpark, spacenumber, gpsaddress, vehicletype, vehiclemake, vehiclemodel, vehiclecolour, issuereasoncode, issuereason, noticelocation, points, notes) set issuereasoncode = right(issuereasoncode, char_length(issuereasoncode) - 2) 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -