【发布时间】:2020-01-07 17:27:00
【问题描述】:
我正在尝试将时间从列附加到日期并在案例陈述中使用
getdate() at time zone 'Central Standard Time'
这是我迄今为止尝试过的
select case when
getdate() at time zone 'Central Standard Time' <=
cast(cast (getdate() at time zone 'Central Standard Time'as date) as datetime) + endtime from tablename where id = 'uniqueid'
1 else 0 end
endtime列的数据类型为nvarchar,时间格式为21:00
这是我得到的错误
Incorrect syntax near the keyword 'from'
我也尝试过使用此解决方案https://stackoverflow.com/a/700647,但仍然出现相同的错误。但是当我这样做时
select CAST(CAST(getdate() at time zone 'Central Standard Time' AS DATE) AS DATETIME) + endtime from tablename where id = 'uniqueid'
我得到了2020-01-07 07:00:00.000的正确回复
这似乎也可以正常工作
select case when
getdate() at time zone 'Central Standard Time' >=
CAST(CAST(CAST(getdate() at time zone 'Central Standard Time'AS DATE) AS DATETIME) + '' + '10:00'as DATETIME)
then 1 else 0
end
返回 1
但是
select case when
getdate() at time zone 'Central Standard Time' <=
cast(CAST(CAST(getdate() at time zone 'Central Standard Time' AS DATE) AS DATETIME) + endtime from table where id = 'uniqueid' as datetime)
then 1 else 0 end
返回Incorrect syntax near the keyword 'where'
我不确定我做错了什么还是限制。
【问题讨论】:
标签: sql sql-server sql-server-2017