2

I have a column Date which is Datetime type. And I have an nvarchar column with the time inside. For example:

    Date(datetime)                            Time(nvarchar)
-----------                                  ----------
2010-06-08 00:00:00.000                         17:30

How can I concatenate them to 2010-06-08 17:30:00.000 as a datetime object?

4

2 回答 2

6

试试这个(它适用于 2005 版及更高版本) -

DECLARE 
      @Date DATETIME 
    , @Time NVARCHAR(5)

SELECT 
      @Date = '2010-06-08 00:00:00.000'
    , @Time = '17:30'   

SELECT @Date + @Time

输出:

2010-06-08 17:30:00.000
于 2013-05-23T12:31:56.397 回答
0

试试这个,我这里的机器上没有安装 SQL Server 2005。我只有甲骨文。但我在我的一个 TSQL 片段文件夹中找到了这个。

SELECT theDate + CAST(theTime AS TIME);
于 2013-05-23T12:35:06.517 回答