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.
| Author |
Topic |
|
Maverick_
Posting Yak Master
107 Posts |
Posted - 2010-11-11 : 11:08:21
|
| Hi all I am trying to do a round up inside a sub-select but can't think of a way to do it.This is my initial Sub-select: (SELECT sum(f_meas.feature_quantity) FROM feat_measurement f_meas WHERE f_meas.measurement_code IN ('TVAL', 'TSDA', 'TSCO, 'TMOV')) as RoundupThis is an Excel equivalent example of what I am trying to achieve with the above Sub-select:sum(roundup(sum('TVAL', 'TSDA', 'TSCO, 'TMOV')/4,0)).Is there a way to do this in SQL? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-11-11 : 11:32:14
|
| I'm not familar with the roundup function, but maybe the ROUND function? |
 |
|
|
Maverick_
Posting Yak Master
107 Posts |
Posted - 2010-11-11 : 11:38:12
|
| Yes, but what I am looking for it to do in SQL is Add up quantity it finds in TVAL, TSDA, TSCO, and TMOV fields, then divide it by 4 and give the total.Is there a way to do that in SQL? |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-11-11 : 11:53:30
|
Maybe:(SELECT ROUND(sum(f_meas.feature_quantity / 4.0), 0)FROMfeat_measurement f_measWHEREf_meas.measurement_code IN ('TVAL', 'TSDA', 'TSCO', 'TMOV')) AS RoundUpIf that doesn't work, please provide DDL, DML and expected output. This link can help you with that:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
Maverick_
Posting Yak Master
107 Posts |
Posted - 2010-11-11 : 12:08:48
|
| Lamprey that did it! Thank you :) |
 |
|
|
|
|
|
|
|