Solved

SQL question

Posted on 2013-01-09
6
191 Views
Last Modified: 2013-01-10
How can I change this query to give me 2 counts - the number of records where "updated = 0" and the number of records where "updated = 1"

select count(*) from case_note
where updated = 1
0
Comment
Question by:HLRosenberger
[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
6 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 38760385
try union...

elect 1, count(*) from case_note
where updated = 1
union all
select 0,count(*) from case_note
where updated = 0
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 167 total points
ID: 38760391
or, do conditional counting

select  count(case where updated = 0 then 1 end),
count(case where updated = 1 then 1 end)
from case_note
0
 
LVL 2

Assisted Solution

by:thombeck
thombeck earned 167 total points
ID: 38760396
Hi,

select 
Sum(case when updated=1 THEN 1 ELSE 0 END),
Sum(case when updated=0 THEN 1 ELSE 0 END)
from case_note

Open in new window

0
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!

 
LVL 32

Assisted Solution

by:awking00
awking00 earned 166 total points
ID: 38760847
select updated, count(*)
from case_note
where updated in (1,2)
group by updated;
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 38762778
Try this, but feel as your queries not clear as whetehr you need two result set else one result with condition for updated.

select 'Number of records where updated = ' + updated  + ' is ' + count(*)
from case_note group by updated;
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 38763931
Thanks,.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

732 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