从SQL Server 2012查询结果中减去小时 [英] Subtract hours from SQL Server 2012 query result

查看:99
本文介绍了从SQL Server 2012查询结果中减去小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在SQL Server 2012 Management Studio中的警报系统信号自动化平台数据库上运行查询,并且遇到了一些麻烦。

I am running queries on an alarm system signal automation platform database in SQL Server 2012 Management Studio, and I am running into some hiccups.

我的查询运行得很好,但是我无法将结果细化到想要的水平。

My queries run just fine, but I am unable to refine my results to the level that I would like.

我正在选择一些格式为 DATETIME 的列,我只想将列中的值减去4小时(即,从GMT到EST) ),然后将 that 值输出到查询结果中。

I am selecting some columns that are formatted as DATETIME, and I simply want to take the value in the column and subtract 4 hours from it (i.e., from GMT to EST) and then output that value into the query results.

我可以找到的有关 DATESUB()的所有文档或类似的命令都显示了带有特定<$语法上的c $ c> DATETIME ,我没有任何具体要求,只有138,000行带有要调整时区的列。

All of the documentation I can find regarding DATESUB() or similar commands are showing examples with a specific DATETIME in the syntax, and I don't have anything specific, just 138,000 rows with columns I want to adjust time zones for.

是我遗漏了一些大东西吗,还是在处理查询结果后是否需要继续手动进行调整?另外,如果有所作为,我具有只读访问级别,并且对以任何方式更改表数据都不感兴趣。

Am I missing something big or will I just need to continue to adjust manually after I being manipulating my query result? Also, in case it makes a difference, I have a read-only access level, and am not interested in altering table data in any way.

推荐答案

对于初学者来说,您需要知道不限于仅对静态值使用函数,可以

Well, for starters, you need to know that you aren't restricted to use functions only on static values, you can use them on columns.

似乎您想要的只是:

SELECT DATEADD(HOUR,-4,YourColumnWithDateTimes)
FROM dbo.YourTable

这篇关于从SQL Server 2012查询结果中减去小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆