• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Select Count 2 columns

I have a table that has a column called afsTransaction

In the column can be any integer from 0 to 10000

I need a single select statement so that I get the UID, count(afsTransactions=0), count(afsTransactions <>0)

My currect (partial) select is attached.
Set	@afsCount = (Select Count(*) 
				from proc_cfa.dbo.P_AvailableForSale
				where	substring(afsSource,4,4) = @DealID
					and
					afsTransaction <> 0)

Open in new window

0
lrbrister
Asked:
lrbrister
1 Solution
 
Patrick MatthewsCommented:
SELECT UID, SUM(CASE WHEN afsTransactions = 0 THEN 1 ELSE 0 END) AS Zeroes, 
    SUM(CASE WHEN afsTransactions <> 0 THEN 1 ELSE 0 END) AS NonZeroes
FROM proc_cfa.dbo.P_AvailableForSale
GROUP BY UID

Open in new window

0
 
lrbristerAuthor Commented:
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now