Solved

SQL syntax

Posted on 2011-09-28
6
221 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server 2008 R2 - Execution Plan 3 31
Creating Alerts in sql sever 2 13
shrink datafile Sql server 4 18
Test a query 23 19
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

10 Experts available now in Live!

Get 1:1 Help Now