If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > mysql query problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-06, 10:25
anandsatchin anandsatchin is offline
Registered User
 
Join Date: Oct 2006
Posts: 4
mysql query problem

Hi guys,

I need to convert a date field(dd/mm/yyyy) into mysql date column(yyyy-mm-dd)

table
========

CREATE TABLE fujitsu_spare_import (
date_temp date NOT NULL default '0000-00-00',
time time NOT NULL default '00:00:00',
scan_type text NOT NULL,
fujitsu_order_number text NOT NULL,
technician_or_shippiment text NOT NULL,
import_status tinyint(1) default '0'
) TYPE=InnoDB;



query
========

LOAD DATA INFILE "P:\\test.csv"
INTO TABLE fujitsu_spare_import
FIELDS TERMINATED BY ','
(str_to_date(date_temp, '%d/%m/%Y'),time,scan_type,fujitsu_order_number);

Example csv file
======

21/06/1921,15:20:45,R,9000804991Test,,0



Database - mysql 5.0
===============

The above query is not working, can anyone pls help me out.

Cheers
Anand

Last edited by anandsatchin; 10-23-06 at 10:44.
Reply With Quote
  #2 (permalink)  
Old 10-23-06, 10:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
add another column to the table, VARCHAR(10), load the date string into this extra column, then run an UPDATE statement with STR_TO_DATE, and finally ALTER the table and drop the extra column
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-23-06, 11:48
anandsatchin anandsatchin is offline
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks ,very muh for the help...

I will use ur suggestion,

update fujitsu_spare_import
set `date_spares`= str_to_date(date_temp,'%d/%m/%Y')
where scan_type like '%R%'

created a new column date_spares and its fine now.

But should there be a way to update while ur using the load query?

Anway thanks once again
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On