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
 SQL Server Development (2000)
 Sum Problem

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-04-07 : 10:30:08

Hi
I have score column(can be 0,1 or 2) and i want to add score based on userid,but i don't want to add if score is "2".
On the other hand,i want to add only score is "1".
How can i get this target?I use sql2000 enterprise manger.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-07 : 10:34:06
[code]Select UserID, Sum(Case when Score <> 2 then Score else 0 end) Score_Total
From table
group by UserID[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-04-07 : 10:49:05
Thanks alot.
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-04-07 : 21:24:15
This is my procedure.But it doesn't work properly.

CREATE PROCEDURE [dbo].[sp_overall]
AS
select UserID,count(ProblemDescription) as noques,sum(case when Chk<>2 then Chk else 0 end) as score
from samplePermAns
group by UserID
GO
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2008-04-07 : 21:26:47
happy coding
now it works.

Thanks again.
Go to Top of Page
   

- Advertisement -