简体   繁体   English

将nvarchar(50)转换为datetime

[英]converting nvarchar(50) to datetime

I am using SQL Server 2005 and am trying to match in a Dimension table the date field with data: 我正在使用SQL Server 2005,并尝试在Dimension表中将日期字段与数据进行匹配:

2012-01-06 00:00:00.000 as a datetime to a staging table with data that comes in as a nvarchar(50) 2012-01-06 15:53:12.040 for example. 例如, 2012-01-06 15:53:12.040 2012-01-06 00:00:00.000作为登台表的datetime ,其中数据以nvarchar(50) 2012-01-06 15:53:12.040 I have tried all of the converts and casts that I can find on the searches but am getting an "Arithmetic overflow error converting expression to data type datetime." 我已经尝试了所有可以在搜索中找到的转换和转换,但是却遇到了“将表达式转换为数据类型为datetime的算术溢出错误”。 error message. 错误信息。

I have updated all of the time values manually in the staging table to have 00:00:00.000 time stamps but still the problem is there. 我已经在登台表中手动更新了所有时间值,以使其具有00:00:00.000时间戳,但问题仍然存在。

Can anyone help please? 有人可以帮忙吗?

Are you just trying to change the data type of the entire column? 您是否只是尝试更改整个列的数据类型?

If so, try this 如果是这样,请尝试

ALTER TABLE table_name
ALTER COLUMN column_name datetime

More info . 更多信息

If you are trying to just modify for a query, you can try this: 如果您只想修改查询,则可以尝试以下操作:

 SELECT convert (...look at link below for options... )

Look here for more info. 在这里查看更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM