SQL DATETIME是否从Excel插入? [英] SQL DATETIME Insert from Excel?

查看:49
本文介绍了SQL DATETIME是否从Excel插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了一个很奇怪的问题,我在excel中有一个列(让我们说列A),它的数据看起来像这样:

So im having a rather strange problem, I have a Column (lets say Column A) in excel that has data that looks like this:

2015年4月11日10:14

4/11/2015 10:14

我还有很多其他列,但是无论如何,在Excel中的SQL Insert语句中,数据(复制时)如下所示:42105.4561921296

I have a bunch of other columns, but anyways in my SQL Insert statement within excel, the data (when copying out) looks like this: 42105.4561921296

="="插入表值('& A1&',等等...)"的数据格式为常规",而日期"列的格式为自定义"是其中的M/DD/YYYY MM/HH类型.

The ="INSERT INTO TABLE VALUES ('"&A1&"', Etc....)" is in the data format of "general" and the Date column is in the format of "Custom" where there is a M/DD/YYYY MM/HH type within.

SQL列的数据类型为DATETIME,因此它当然不接受它得到的怪异数字.

The SQL Column is of the data type DATETIME, so it of course doesn't accept the weird number it gets.

有什么想法吗?更改"SQL INSERT"列的格式不会更改结果.

Any ideas? changing the format of the "SQL INSERT" column doesn't change the results.

推荐答案

您是正确的-Excel格式仅更改数字显示的显示方式,而不更改单元格的基础值.在这种情况下,该单元格的值是一个excel日期时间值,它是自1900年1月1日以来的天数,时间为小数.

You are right - Excel formats only changes the way the numbers are displayed, not the underlying value of the cell. In this case, the value of the cell is an excel date-time value, which is the # of days since 1/1/1900, with decimals for the time.

我建议使用Excel的 TEXT 函数将Excel的数字日期时间值转换为可以插入SQL的文本字符串:

I'd recommend using Excel's TEXT function to convert Excel's numeric date-time value to a text string that can be inserted into SQL:

代替:

INSERT INTO TABLE VALUES ('"&A1&"', Etc....)"

尝试:

INSERT INTO TABLE VALUES ('"&TEXT(A1,"YYYY-MM-DD HH:MM")&"', Etc...)"

这篇关于SQL DATETIME是否从Excel插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆