[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Select Count 2 columns

Posted on 2011-02-25
2
Medium Priority
?
341 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

649 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