Solved

SELECT Count with CASE

Posted on 2006-07-10
2
491 Views
Last Modified: 2012-06-22
Hi guys, I am trying to do a SQL statement fo this matter:

I need to return 1 (for true) if in my table user_tables I got for my column isJoin  the count of 6 .
in addition to the count, I need check there is no value of 0 on that column.   Example:

IsJoin:  1 2 3 0 0 4
Count = 6 , but got 2 zero, So i would return false.

Example:

IsJoin :  1 2 3 4 5 6
count = 6, no zero:   Return true.


I didnt find the way to do it in SQl.. can you help ?
0
Comment
Question by:PhilippeRenaud
2 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17073682
Hi PhilippeRenaud,

Select Case When (Select Sum(Case When IsJoin = 0 Then 0 Else 1 End) As [Count] From User_Tables) = 6 Then 1 Else 0 End As Result

For example.

Tim Cottee
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 17073685

SELECT CASE WHEN(Select Count(isJoin) FROM user_tables where isJoin >0 ) = 6 then 1 ELSE o END as Status
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

785 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