Solved

Select Count 2 columns

Posted on 2011-02-25
2
322 Views
Last Modified: 2012-05-11
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
Comment
Question by:lrbrister
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:lrbrister
Comment Utility
Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now