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 |
alanw
Starting Member
2 Posts |
Posted - 2010-09-20 : 07:53:57
|
HiWe have the value 'inv' for in a table to signify an Invoice transaction. I need to count how many time this value appears within a certain date criteria, it works but returns very wild numbers.Code is:SUM(CASE WHEN st_trantype IN ('inv') THEN 1 ELSE 0 END) AS Doc_CountSum distinct doesn't appear to be any goodAll help appriciatedAlan A.J.Wilkes |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2010-09-20 : 07:58:24
|
sample data and output ? |
 |
|
umaoua
Starting Member
1 Post |
Posted - 2010-09-20 : 08:18:44
|
YOU can use count function instead of sum.count(st_trantype) where st_trantype = 'inv' |
 |
|
kunal.mehta
Yak Posting Veteran
83 Posts |
Posted - 2010-09-20 : 08:40:45
|
SUM(CASE WHEN st_trantype =('inv') THEN 1 ELSE 0 END) AS Doc_Count |
 |
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-09-20 : 08:43:07
|
use:select count(*) from Table where st_transtype in ('inv') query will be faster and you should get OK results :) |
 |
|
alanw
Starting Member
2 Posts |
Posted - 2010-09-20 : 09:21:22
|
Hi AllThanks everso :-) will try them allAlanA.J.Wilkes |
 |
|
|
|
|