Solved

SQL syntax

Posted on 2011-09-28
6
232 Views
Last Modified: 2012-05-12
I am getting a compile error as follows:

Incorrect syntax near the keyword 'AND'.

How do I rewrite this script -- so that both parameters are checked for '0' in order to be counted.
, COUNT(case NetworkCause WHEN 0 AND case PrepaidCause WHEN 0 THEN NetworkCause END)

Open in new window

0
Comment
Question by:amillyard
[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
  • 3
  • 2
6 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36717182
COUNT(CASE WHEN NetworkCause = 0 AND PrepaidCause = 0 THEN NetworkCause END)
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36717189
Note that that is the same thing, in this instance, as:

COUNT(CASE WHEN NetworkCause = 0 AND PrepaidCause = 0 THEN 0 END)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36717191
COUNT(CASE WHEN NetworkCause + PrepaidCause = 0 THEN NetworkCause END)
0
Independent Software Vendors: 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 33

Expert Comment

by:knightEknight
ID: 36717199
hmm, my suggestion assumes that both columns contain only positive values or 0 -- if this is not the case then scratch it.  :)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36717202
but points to matthewpatrick pls
0
 

Author Closing Comment

by:amillyard
ID: 36717289
matthewspatrick:  many thanks - works great :-)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

756 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