开发者

SQL Convert Int to Time

i'm trying to import data from a text file to an SQL database. The file is using TAB not , to separate fields. My issue on import has been that when I write the Time which is given as an Int it completely messes up on import.

Part of the text file:

North   Felix   2011-07-01  0422    0.47    0012    0.69    2109    0.55    1311    1.44
North   Felix   2011-07-02  0459    0.43    0048    0.72    2140   开发者_如何学Go 0.55    1342    1.47
North   Felix   2011-07-03  0533    0.41    0123    0.75    2213    0.57    1412    1.46
North   Felix   2011-07-04  0605    0.41    0158    0.79    2244    0.59    1441    1.41

My query result:

INSERT INTO `dbc`.`history_long` (`Region`,`Location`,`Date`,`LT1-time`,`LT1-height`,`HT1-time`,`HT1-height`,`LT2-time`,`LT2-height`,`HT2-time`,`HT2-height`) 
values ('North','Felix','2011:00:00','422:00:00','0.47','12:00:00','0.69','2109:00:00','0.55','1311:00:00','1.44'),
('North','Felix','2011:00:00','459:00:00','0.43','48:00:00','0.72','2140:00:00','0.55','1342:00:00','1.47'),
('North','Felix','2011:00:00','533:00:00','0.41','123:00:00','0.75','2213:00:00','0.57','1412:00:00','1.46'),
('North','Felix','2011:00:00','605:00:00','0.41','158:00:00','0.79','2244:00:00','0.59','1441:00:00','1.41'),

The issue is for example L2-time becomes 2109:00:00 in the time column. Is there a way to convert this from Int to Time?


Here's how you could convert an int like 0422 to a time value:

SELECT CAST('00:00' AS time)
     + INTERVAL (@IntValue DIV 60) HOUR
     + INTERVAL (@IntValue % 60) MINUTE

Without seeing your import query it's impossible to say how you could actually apply it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜