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 |
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2007-07-03 : 06:06:55
|
| Hi, I'm returning records with a select statement, and one of the columns holds the number of free spaces.So;ID Freespaces12 513 211 614 -118 017 6I'm using a -1 to indicate that this field should not be shown on the website, a 0 will just show a 0.Now, I want to give the total number of freespaces and it should return (5 + 2 + 6 + 0 + 6) = 19So it should ignore the -1 values.Any idea how this can be done? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-07-03 : 06:29:58
|
| select sum(case when Freespaces > 0 then Freespaces else 0 end) as Freespacesfrom MyTable_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-03 : 06:40:52
|
| select sum(Freespaces) as Freespacesfrom MyTablewhere Freespaces > 0 Peter LarssonHelsingborg, Sweden |
 |
|
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2007-07-03 : 06:58:55
|
| Why didn't I think of that.... |
 |
|
|
|
|
|