![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have a table with a DATE field that can be NULL and the default is NULL. The table definition is shown below with all the fields not shown except the one in question. CREATE TABLE MyTable ( ... SepDate DATE NULL DEFAULT NULL, ... ) ENGINE = InnoDB; I populate MyTable using a csv file that comes directly from an Excel spreadsheet. The SQL command is: LOAD DATA LOCAL INFILE '2011-03-28.csv' INTO TABLE Brios.Brio2011_03_28 FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' ... more omitted The terminator is a pipe symbol because I'm sure it does not appear as data in the Excel file. It all works well except for the following minor irritation. Most, not all, of the DATE columns in the csv file are blank, they appear as two consecutive pipe symbols with nothing in between, i.e., ||. After the LOAD these blank DATE values (||) appear in MyTable as '0000-00-00'. I would like them to appear as NULL. I realize I can do a query that would replace all '0000-00-00' with NULL but I was hoping there would be another way. |
#3
| |||
| |||
|
|
In your case, you can do something like: SET SepDate = CASE @SepDate WHEN '' THEN NULL ELSE @SepDate END |

#4
| |||
| |||
|
|
El 31/03/2011 9:34, "Álvaro G. Vicario" escribió/wrote: In your case, you can do something like: SET SepDate = CASE @SepDate WHEN '' THEN NULL ELSE @SepDate END |
|
Or maybe: SET SepDate = CASE @SepDate WHEN '0000-00-00' THEN NULL ELSE @SepDate END |
I haven't really tested it ![]() |
#5
| |||
| |||
|
|
El 31/03/2011 9:34, "lvaro G. Vicario" escribi/wrote: In your case, you can do something like: SET SepDate = CASE @SepDate WHEN '' THEN NULL ELSE @SepDate END Or maybe: SET SepDate = CASE @SepDate WHEN '0000-00-00' THEN NULL ELSE @SepDate END CASE is complete overkill when you are only testing one thing for 2 |
#6
| |||
| |||
|
|
In article<in1bf4$tbg$2 (AT) dont-email (DOT) me>, lvaro G. Vicario<alvaro.NOSPAMTHANX (AT) demogracia (DOT) com.invalid> wrote: El 31/03/2011 9:34, "Álvaro G. Vicario" escribió/wrote: In your case, you can do something like: SET SepDate = CASE @SepDate WHEN '' THEN NULL ELSE @SepDate END Or more concisely: SET SepDate = NULLIF(@SepDate,'') |

![]() |
| Thread Tools | |
| Display Modes | |
| |