Subtract hours from SQL Server 2012 query result

adalious

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.

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.

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.

Lamak

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.

It seems that what you want is simply:

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

subtract 6 hours from the default getdate() azure sql

分類Dev

Move database from SQL Server 2012 to 2008

分類Dev

Subtract 12 hours from timestamp (batch file)

分類Dev

SQL Server How to output one table result from multiple results with a WHILE query

分類Dev

SQL Server query result needs to give different values in two columns of the same name from the same source table

分類Dev

Rollback in single stored procedure for forloop & insert query in SQL Server 2012

分類Dev

Looping result from SQL select query

分類Dev

Query SQL to subtract two fields

分類Dev

Substract query from another query in SQL Server

分類Dev

How to get COUNT(*) from one partition of a table in SQL Server 2012?

分類Dev

Delete duplicate records from SQL Server 2012 table with identity

分類Dev

Take Current MYSQL Timestamp And Subtract It From 24 Hours

分類Dev

Add extra rows in result set of query with dummy data in sql server

分類Dev

SQL Server - Merge multiple query results into one result set

分類Dev

How to give numbers to the result after executing the query in sql server?

分類Dev

SQL 2012 Simplify Query Union

分類Dev

Query from multiple XML columns in SQL Server

分類Dev

Numbering islands in SQL Server 2012

分類Dev

SQL Server 2012 Pivot Table

分類Dev

Restore SQL Server 2012 error

分類Dev

Get Distinct rows from a result of JOIN in SQL Server

分類Dev

Assembly Language - Subtract edx from ecx and place result in ebx

分類Dev

to include a header into result of sQL query

分類Dev

SQL Server 2012: How to get up to 5 hierarchy levels of data from original to derived product table

分類Dev

SQL Server Query not working when executed from PHP

分類Dev

SQL Server Query using results from table to Call function

分類Dev

Convert user access query from postgreSQL to SQL Server

分類Dev

Exception while excecuting insert query to SQL Server from c#

分類Dev

No process is on the other end of the pipe (SQL Server 2012)

Related 関連記事

  1. 1

    subtract 6 hours from the default getdate() azure sql

  2. 2

    Move database from SQL Server 2012 to 2008

  3. 3

    Subtract 12 hours from timestamp (batch file)

  4. 4

    SQL Server How to output one table result from multiple results with a WHILE query

  5. 5

    SQL Server query result needs to give different values in two columns of the same name from the same source table

  6. 6

    Rollback in single stored procedure for forloop & insert query in SQL Server 2012

  7. 7

    Looping result from SQL select query

  8. 8

    Query SQL to subtract two fields

  9. 9

    Substract query from another query in SQL Server

  10. 10

    How to get COUNT(*) from one partition of a table in SQL Server 2012?

  11. 11

    Delete duplicate records from SQL Server 2012 table with identity

  12. 12

    Take Current MYSQL Timestamp And Subtract It From 24 Hours

  13. 13

    Add extra rows in result set of query with dummy data in sql server

  14. 14

    SQL Server - Merge multiple query results into one result set

  15. 15

    How to give numbers to the result after executing the query in sql server?

  16. 16

    SQL 2012 Simplify Query Union

  17. 17

    Query from multiple XML columns in SQL Server

  18. 18

    Numbering islands in SQL Server 2012

  19. 19

    SQL Server 2012 Pivot Table

  20. 20

    Restore SQL Server 2012 error

  21. 21

    Get Distinct rows from a result of JOIN in SQL Server

  22. 22

    Assembly Language - Subtract edx from ecx and place result in ebx

  23. 23

    to include a header into result of sQL query

  24. 24

    SQL Server 2012: How to get up to 5 hierarchy levels of data from original to derived product table

  25. 25

    SQL Server Query not working when executed from PHP

  26. 26

    SQL Server Query using results from table to Call function

  27. 27

    Convert user access query from postgreSQL to SQL Server

  28. 28

    Exception while excecuting insert query to SQL Server from c#

  29. 29

    No process is on the other end of the pipe (SQL Server 2012)

ホットタグ

アーカイブ