Solved

SQL syntax

Posted on 2011-09-28
6
224 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
  • 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
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.

 
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

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now