Forum Moderators: coopster

Message Too Old, No Replies

Import few digits and trim rest

         

sfast

7:21 pm on Jul 13, 2007 (gmt 0)

10+ Year Member



I have to import a file to MySQL database with a numeric field that has values as -

007234560999.

When I import that file, this field should import 723456 only. I mean should trim (00) from left and accept 6 digits and then reject any other digits.

How can I do it?

The only way I could think of it is import the original data to the table and trim the field values and store it again.

Thanks

coopster

8:05 pm on Jul 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just define the column in your table properly and upon import you won't have to do any type of conversion whatsoever.

sfast

2:35 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



Thanks for responding, Coopster.
But how do I define the column in the table to skip 00 at start?

coopster

2:49 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



More than likely as an INTEGER, but you'll have to make that decision based on the largest value expected. Probably an UNSIGNED INTEGER.

[dev.mysql.com...]

whoisgregg

4:07 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you were going to preprocess the file with PHP, you could use substr [php].

echo substr("007234560999", 2, 6); // 723456

sfast

4:55 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



Thanks everybody , thats what I did. used substr.