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
 General SQL Server Forums
 New to SQL Server Programming
 Count field where value gt than 0

Author  Topic 

Stan1978
Starting Member

31 Posts

Posted - 2011-08-22 : 04:42:25
Thanks for reading and the continued help.

I have a table structured -

Trans--------DeltaCash

Correction---100
Dep----------50
Correction----0
Correction---50

etc . .

I would like to count all Corrections where DeltaCash column is greater than 0.

For the data shown 2.


Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-22 : 04:46:01
[code]SELECT COUNT(CASE WHEN Trans='Correction' AND DeltaCash > 0 THEN 1 ELSE NULL END) AS CntValue,
.....
FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-22 : 04:48:54
[code]
select count(*)
from yourtable
where Trans = 'Correction'
and DeltaCash > 0
[/code]


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

Go to Top of Page

Stan1978
Starting Member

31 Posts

Posted - 2011-08-22 : 04:53:44
Works as expected thanks I was basically there just got some syntax wrong.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-22 : 04:56:59
np...you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -