SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


COUNT


COUNT

Author
Message
sharonsql2013
sharonsql2013
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1224 Visits: 1265
This is what I need to actually count.
COUNT(*)round
from CTE1
where
( (Cte1.Roundtables = '1' OR Cte1.Roundtables= 'N/A')
AND
(CTE1.IsVideo = '1' OR CTE1.IsVideo = 'N/A'))


SO, I am trying to count the # of Roundtables which have either a number or 'N/A' ( mentioned in the CTE)
and the count of IsVideo if its a number OR ;N/A.
and then do an AND on both their respective counts.

Kindly advise
sharonsql2013
sharonsql2013
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1224 Visits: 1265
Let me mention that when I individually execute without the AND part for each , I get the count as 3 and 8 respectively .
I am expecting the answer to be 3 but the and brings 0
Sean Lange
Sean Lange
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59065 Visits: 17945
sharonsql2013 (1/8/2014)
This is what I need to actually count.
COUNT(*)round
from CTE1
where
( (Cte1.Roundtables = '1' OR Cte1.Roundtables= 'N/A')
AND
(CTE1.IsVideo = '1' OR CTE1.IsVideo = 'N/A'))


SO, I am trying to count the # of Roundtables which have either a number or 'N/A' ( mentioned in the CTE)
and the count of IsVideo if its a number OR ;N/A.
and then do an AND on both their respective counts.

Kindly advise


Pretty sparse on details here. Remember we can't see you screen. However I suspect you are getting 0 because your logic seems a little suspect to me. You must have a row that that RoundTables = 1 or N/A AND IsVideo = 1 or N/A.

This is the same thing as RoundTables in ('1', N/A') AND IsVideo in ('1', 'N/A'). I have a feeling that is not actually what you want though.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
sharonsql2013
sharonsql2013
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1224 Visits: 1265
Yes so I am counting RoundTables in ('1', N/A') AND IsVideo in ('1', 'N/A').
and then need to do an and between these to counts.

Should I separately count and then add ?
Sean Lange
Sean Lange
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59065 Visits: 17945
sharonsql2013 (1/8/2014)
Yes so I am counting RoundTables in ('1', N/A') AND IsVideo in ('1', 'N/A').
and then need to do an and between these to counts.

Should I separately count and then add ?


Wouldn't changing the AND to OR solve the issue?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
ChrisM@home
ChrisM@home
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4914 Visits: 10605
Sean Lange (1/8/2014)
sharonsql2013 (1/8/2014)
Yes so I am counting RoundTables in ('1', N/A') AND IsVideo in ('1', 'N/A').
and then need to do an and between these to counts.

Should I separately count and then add ?


Wouldn't changing the AND to OR solve the issue?


I reckon Sean's nailed it here. Try running this, it will tell you:

SELECT 
Roundtables,
IsVideo,
COUNT(*)
FROM CTE1
WHERE Cte1.Roundtables IN ('1', 'N/A')
OR IsVideo IN ('1', 'N/A')
GROUP BY Roundtables, IsVideo




Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search