Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Using sum and cast together

Author  Topic 

dougancil
Posting Yak Master

217 Posts

Posted - 2010-11-04 : 13:23:20
I'm trying to sum a column as well as round a column up to the nearest minute. Here's 2 queries I'm running, but I'd like to combine them in to one. Can anyone offer any suggestions:

Query 1
select name, employeenumber, sum (ontime) as totalminutes into scratchpad2
from scratchpad1
where date between '5/1/2010' and '5/15/2010'
group by employeenumber, name
order by employeenumber asc

Query 2
select totalminutes, (cast (totalminutes as decimal (10,2))) as realtime
from scratchpad1

Thank you

Doug

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-11-04 : 18:54:00
what do you mean by "combine" ? How do you want the result to looks like ?

Pls post some sample data and expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dougancil
Posting Yak Master

217 Posts

Posted - 2010-11-05 : 11:29:16
I want to be able to sum the ontime and round it to the nearest minute. Right now that takes two queries, I'd like to combine it into one query.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-11-06 : 08:24:52
[code]
select name, employeenumber, cast(sum (ontime) as decimal(10,2)) as totalminutes into scratchpad2
from scratchpad1
where date between '5/1/2010' and '5/15/2010'
group by employeenumber, name
order by employeenumber asc
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-08 : 05:46:35
Also make sure to use unambigiuos date formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -