SQL - Rounding datetime and adding the result as an additional field for easy analysis

We currently have multiple tables that includes a datetime stamp which are updated every 10 seconds. we would like to do analysis on this data crossing tables via the datetime stamp and align records say within that 10 second window. As a record may have been placed at say 10:12:01 and a record we wish to match in another table say at 10:12:08 is it possible to create a calculated field that looks at the timestamp in individual table and rounds up say to the nearest 10 seconds so both the above would appear as 10:12:10

timestamp   rounded    data1 data2   data3   etc.......
10:12:01        10:12:10   xxxx    xxxx     xxxxx
10:12:08        10:12:10   xxxx    xxxx     xxxxx
10:12:11        10:12:20
10:12:15        10:12:20

Would this be achieved via a stored procedure or is there another way of adding this a calculated field. I would like to do this within SQL to make doing the analysis life easier.

Am new to this so any assistance would be appreciated.
S
SimonJohnGAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
Use a computed column to add it to the table itself.  SQL will instantiate the column any time it's reference.

ALTER TABLE table_name
ADD timestamp_rounded AS DATEADD(SECOND, DATEDIFF(SECOND, '20000101', getdate()) / 10 * 10, '20000101')
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
SimonJohnG, do you still need help with this question?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.