从SQL Server 2008 R2中的年份,年份和小时获取日期时间 [英] Get a datetime from year, day of the year and hour in SQL Server 2008 R2
问题描述
ID,Year,DAY,HOUR&值
,其中 DAY
包含一年中的日期(从1到366)和 HOUR
表示一天的时间(从0到23)。 我希望创建一个新的datetime列,并使用从 Year,DAY& HOUR
列。
我应该使用什么SQL函数从其中创建 DateTime
部分?
SQL Server 2012有 DATETIMEFROMPARTS
,但没有等同的功能 SQL Server 2008 R2
declare @Year int = 2003
declare @Day int = 100
declare @Hour int = 13
select dateadd(hour,@Hour ,dateadd(dayofyear,@Day - 1,dateadd(year,@Year - 1900,0)))
I have a table in a Microsft SQL Server 2008 R2, which came from an outside source. The columns of the are as follows: ID, Year, DAY, HOUR & Value
, where DAY
contains the day of the year (from 1 to 366) and HOUR
represents the hour of the day (from 0 to 23).
I wish to create a new datetime column and populate it with the dateTime created from the data in Year, DAY & HOUR
columns.
What SQL function should I use to create the DateTime
from its parts?
SQL Server 2012 has DATETIMEFROMPARTS
, but there is no equivalent function for SQL Server 2008 R2
declare @Year int = 2003
declare @Day int = 100
declare @Hour int = 13
select dateadd(hour, @Hour, dateadd(dayofyear, @Day - 1, dateadd(year, @Year - 1900, 0)))
这篇关于从SQL Server 2008 R2中的年份,年份和小时获取日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!