[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sum total duration

Posted on 2011-05-13
6
Medium Priority
?
593 Views
Last Modified: 2012-05-11
Hi Experts,

I would like to request Experts help. Is that any possibilities to build MSSQL formula for total duration at column “Total_Duration” based on data at column TimeIN(time) and TimeOUT(time). Intent to add this formula at “Computed Column Specification” at ( formula) row. Hope Experts will help to create this formula.


0
Comment
Question by:Cartillo
  • 4
6 Comments
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35752980
you can use
TimeIN-TimeOUT

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35752986
sorry

TimeOUT-TimeIN

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35753029
 (datediff(MINUTE,[TimeOUT],[TimeIN])) 

 (datediff(HOUR,[TimeOUT],[TimeIN])) 

 (datediff(SECOND,[TimeOUT],[TimeIN]))

Open in new window


you can use either of the above 3 methods to get time difference in minutes,HOURS or SECONDS respectively.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 9

Accepted Solution

by:
mayank_joshi earned 1600 total points
ID: 35753056
sorry the above will give negative values.it should be:-

(datediff(MINUTE,[TimeIN],[TimeOUT])) 

 (datediff(HOUR,[TimeIN],[TimeOUT])) 

 (datediff(SECOND,[TimeIN],[TimeOUT]))

Open in new window

0
 
LVL 4

Assisted Solution

by:qasim_md
qasim_md earned 400 total points
ID: 35753607
select DATEDIFF(hh,getdate(), getdate() +2)--+2 is nothing but 2 days

Assign your columns replacing the getdate() and remove the +2.
0
 

Author Closing Comment

by:Cartillo
ID: 35820687
Hi,

Thanks for the help
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question