I have a time field in a mssql 2008 database that I want to do something to the effect of:
Timespent = x.sum(x => x.AmountOfTime);
Where AmountOfTime is a time MSSQL field. Sum seems to only work on decimals, how can I add these columns?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You probably want to convert the periods to intervals – if necessary, by subtracting the start time from the end time. Note that the TIME type represents an instant, not a duration. In standard SQL, you want INTERVAL HOUR TO SECOND. I’m not sure whether Microsoft supports that – there are other major DBMS that do not. If you are stuck with TIME, you should be able to subtract TIME ’00:00:00′ from the values and get something workable (that would be an INTERVAL).
One particular advantage of intervals is that you can indeed add them up via SUM.
For the details, you can manual bash at MSDN (or via Google) as well as I can.