?
Solved

Select Count 2 columns

Posted on 2011-02-25
2
Medium Priority
?
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 34980325
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
ID: 34980653
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

764 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