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 2005 Forums
 Transact-SQL (2005)
 Summing text values

Author  Topic 

alanw
Starting Member

2 Posts

Posted - 2010-09-20 : 07:53:57
Hi

We 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_Count

Sum distinct doesn't appear to be any good

All help appriciated

Alan


A.J.Wilkes

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-09-20 : 07:58:24
sample data and output ?
Go to Top of Page

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'
Go to Top of Page

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
Go to Top of Page

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 :)
Go to Top of Page

alanw
Starting Member

2 Posts

Posted - 2010-09-20 : 09:21:22
Hi All

Thanks everso :-) will try them all


Alan

A.J.Wilkes
Go to Top of Page
   

- Advertisement -