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
Solved

SELECT Count with CASE

Posted on 2006-07-10
2
497 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 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