Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将日期时间字符串拆分为不同的列_Sql_Sql Server - Fatal编程技术网

Sql 将日期时间字符串拆分为不同的列

Sql 将日期时间字符串拆分为不同的列,sql,sql-server,Sql,Sql Server,我有一句话: ,DATEADD(s, C.[Timestamp], CONVERT(DATETIME, '1-1-1970 00:00:00')) As "Timestamp" 其中时间戳被解析为日期时间格式 输出为: 2017-04-19 19:40:20.000 这很好,但我想将日期和时间拆分为多个列。比如YYYY,MM,DD,HH等等 有人知道吗 PS:纯sql。SQL Server 2016使用日期部分 使用日期部分 使用日期部分使用日期部分 SELECT DATEPART(ye

我有一句话:

,DATEADD(s, C.[Timestamp], CONVERT(DATETIME, '1-1-1970 00:00:00')) As "Timestamp"
其中时间戳被解析为日期时间格式

输出为:

2017-04-19 19:40:20.000
这很好,但我想将日期和时间拆分为多个列。比如YYYY,MM,DD,HH等等

有人知道吗

PS:纯sql。SQL Server 2016使用日期部分

使用日期部分

使用日期部分使用日期部分
SELECT DATEPART(year, '12:10:30.123')  
    ,DATEPART(month, '12:10:30.123')  
    ,DATEPART(day, '12:10:30.123')  
    ,DATEPART(dayofyear, '12:10:30.123')  
    ,DATEPART(weekday, '12:10:30.123');