473,372 Members | 1,244 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Supress result 0


I have the following code to SUM based on one field but want to be able
to not show rows which result is 0.
========================
SELECT Headers.employee_id AS Employee#,
SUM(CASE Headers.scan_type WHEN 'I' THEN 1 ELSE 0 END) AS SIP,
SUM(CASE Headers.scan_type WHEN 'F' THEN 1 ELSE 0 END) AS PUP,
SUM(CASE Headers.scan_type WHEN 'Q' THEN 1 ELSE 0 END) AS CMT,
SUM(CASE Headers.scan_type WHEN 'M' THEN 1 ELSE 0 END) AS CONS,
SUM(CASE Headers.scan_type WHEN '\' THEN 1 ELSE 0 END) AS HIP,
SUM(CASE Headers.scan_type WHEN 'U' THEN 1 ELSE 0 END) AS HOP,
SUM(CASE Headers.scan_type WHEN '^' THEN 1 ELSE 0 END) AS INSTA,
SUM(CASE Headers.scan_type WHEN 'L' THEN 1 ELSE 0 END) AS ONRD,
SUM(CASE Headers.scan_type WHEN 'B' THEN 1 ELSE 0 END) AS POD,
SUM(CASE Headers.scan_type WHEN 'G' THEN 1 ELSE 0 END) AS PUX,
SUM(CASE Headers.scan_type WHEN '#' THEN 1 ELSE 0 END) AS ROP,
SUM(CASE Headers.scan_type WHEN 'J' THEN 1 ELSE 0 END) AS SOP,
SUM(CASE Headers.scan_type WHEN 'N' THEN 1 ELSE 0 END) AS STAT,
SUM(CASE Headers.scan_type WHEN 'R' THEN 1 ELSE 0 END) AS UNCON,
SUM(CASE Headers.scan_type WHEN '<' THEN 1 ELSE 0 END) AS
USPS_PSP,
SUM(CASE Headers.scan_type WHEN '\"' THEN 1 ELSE 0 END) AS RIP,
COUNT (Scans.header_index) AS EmpTot
FROM Headers INNER JOIN
Scans ON Headers.header_index = Scans.header_index
WHERE (Scans.datetime BETWEEN '06/18/2003 00:00:00' AND
'06/19/2003 23:59:00')
GROUP BY Headers.employee_id
ORDER BY Headers.employee_id
===============================

Any ideas?
Thanks,
Manuel

--
Posted via http://dbforums.com
Jul 20 '05 #1
9 2632

It does not like "WHERE 0"

--
Posted via http://dbforums.com
Jul 20 '05 #2
I don't see WHERE 0 anywhere in my suggested solution.
Can you post what you ran?

Steve

MB95547 wrote:
It does not like "WHERE 0"

--
Posted via http://dbforums.com


Jul 20 '05 #3

SELECT *
FROM
(
SELECT Headers.employee_id AS Employee#,
SUM(CASE Headers.scan_type WHEN 'I' THEN 1 ELSE 0 END) AS SIP,
SUM(CASE Headers.scan_type WHEN 'F' THEN 1 ELSE 0 END) AS PUP,
SUM(CASE Headers.scan_type WHEN 'Q' THEN 1 ELSE 0 END) AS CMT,
SUM(CASE Headers.scan_type WHEN 'M' THEN 1 ELSE 0 END) AS CONS,
SUM(CASE Headers.scan_type WHEN '\' THEN 1 ELSE 0 END) AS HIP,
SUM(CASE Headers.scan_type WHEN 'U' THEN 1 ELSE 0 END) AS HOP,
SUM(CASE Headers.scan_type WHEN '^' THEN 1 ELSE 0 END) AS INSTA,
SUM(CASE Headers.scan_type WHEN 'L' THEN 1 ELSE 0 END) AS ONRD,
SUM(CASE Headers.scan_type WHEN 'B' THEN 1 ELSE 0 END) AS POD,
SUM(CASE Headers.scan_type WHEN 'G' THEN 1 ELSE 0 END) AS PUX,
SUM(CASE Headers.scan_type WHEN '#' THEN 1 ELSE 0 END) AS ROP,
SUM(CASE Headers.scan_type WHEN 'J' THEN 1 ELSE 0 END) AS SOP,
SUM(CASE Headers.scan_type WHEN 'N' THEN 1 ELSE 0 END) AS STAT,
SUM(CASE Headers.scan_type WHEN 'R' THEN 1 ELSE 0 END) AS UNCON,
SUM(CASE Headers.scan_type WHEN '<' THEN 1 ELSE 0 END) AS
USPS_PSP,
SUM(CASE Headers.scan_type WHEN '\"' THEN 1 ELSE 0 END) AS RIP,
COUNT (Scans.header_index) AS EmpTot
FROM Headers INNER JOIN
Scans ON Headers.header_index = Scans.header_index
WHERE (Scans.datetime BETWEEN '06/18/2003 00:00:00' AND
'06/19/2003 23:59:00')
GROUP BY Headers.employee_id
-- ORDER BY Headers.employee_id
)
T
WHERE 0
ORDER BY Employee#

--
Posted via http://dbforums.com
Jul 20 '05 #4

Thanks Diego.
I still see the same results...
The problem is that the SUM(CASE ... creates a column for each case.
If there was a way of comparing the reult for SIP, PUP, ETC . and based
on that not show the column, ...

Rgds,

--
Posted via http://dbforums.com
Jul 20 '05 #5
What do you mean by "WHERE 0" ? Do you mean

where SIP = 0 OR PUP = 0 OR CMT = 0 ...

or do you mean

where SIP = 0 AND PUP = 0 AND CMT = 0 AND ...

or something else?

Also, be careful with your date range. If Scans.datetime is
not smalldatetime, you will lose the last minute of every day. It is
better to say

where (Scans.datetime >= '20000618' and Scans.datetime < '20000619')

also because mm/dd/yyyy is not portable to different language settings,
but yyyymmdd is.

SK

MB95547 wrote:
SELECT *
FROM
(
SELECT Headers.employee_id AS Employee#,
SUM(CASE Headers.scan_type WHEN 'I' THEN 1 ELSE 0 END) AS SIP,
SUM(CASE Headers.scan_type WHEN 'F' THEN 1 ELSE 0 END) AS PUP,
SUM(CASE Headers.scan_type WHEN 'Q' THEN 1 ELSE 0 END) AS CMT,
SUM(CASE Headers.scan_type WHEN 'M' THEN 1 ELSE 0 END) AS CONS,
SUM(CASE Headers.scan_type WHEN '\' THEN 1 ELSE 0 END) AS HIP,
SUM(CASE Headers.scan_type WHEN 'U' THEN 1 ELSE 0 END) AS HOP,
SUM(CASE Headers.scan_type WHEN '^' THEN 1 ELSE 0 END) AS INSTA,
SUM(CASE Headers.scan_type WHEN 'L' THEN 1 ELSE 0 END) AS ONRD,
SUM(CASE Headers.scan_type WHEN 'B' THEN 1 ELSE 0 END) AS POD,
SUM(CASE Headers.scan_type WHEN 'G' THEN 1 ELSE 0 END) AS PUX,
SUM(CASE Headers.scan_type WHEN '#' THEN 1 ELSE 0 END) AS ROP,
SUM(CASE Headers.scan_type WHEN 'J' THEN 1 ELSE 0 END) AS SOP,
SUM(CASE Headers.scan_type WHEN 'N' THEN 1 ELSE 0 END) AS STAT,
SUM(CASE Headers.scan_type WHEN 'R' THEN 1 ELSE 0 END) AS UNCON,
SUM(CASE Headers.scan_type WHEN '<' THEN 1 ELSE 0 END) AS
USPS_PSP,
SUM(CASE Headers.scan_type WHEN '\"' THEN 1 ELSE 0 END) AS RIP,
COUNT (Scans.header_index) AS EmpTot
FROM Headers INNER JOIN
Scans ON Headers.header_index = Scans.header_index
WHERE (Scans.datetime BETWEEN '06/18/2003 00:00:00' AND
'06/19/2003 23:59:00')
GROUP BY Headers.employee_id
-- ORDER BY Headers.employee_id
)
T
WHERE 0
ORDER BY Employee#

--
Posted via http://dbforums.com


Jul 20 '05 #6

Sorry, I pressed the wrong key .... this is the rest of my reply ...

and in the second option you metion "WHERE 0" ...
unless you meant something else or you're thinking about a different DB
engine than MSSQL "HAVING 0" and "WHERE 0" are syntactically incorrect.

Thanks,

--
Posted via http://dbforums.com
Jul 20 '05 #7

Thanks Erland. Now I see what the confusion was.
Sorry Steve.

Rgds,

--
Posted via http://dbforums.com
Jul 20 '05 #8
Jeepers! Thanks for the tip, Erland! I often use angle brackets -
and I'm not interested in giving them up just to accommodate this
madness. Maybe I'll add a suitable comment to my signature line.

Steve
<dbforums.com needs to stop corrupting Usenet news messages>

Erland Sommarskog wrote:
MB95547 (me*********@dbforums.com) writes:

Steve, when you first replied, you have a couple of suggestions in one
of them you sugest adding "HAVING 0"


No, Steve didn't say that. You are victim for a bug in the interface at
dbforums.com. Steve said:

having [whatever] [] 0

except that he didn't use square brackets, but angle brackets.
Apparently dbforums.com, does not handle characters that are special
to HTML when they get article from Usenet. In my opinion this is a
serious problem and I suggest that you raise this issue with them.

You can view the entire thread on Google. Since dbforums is likely to
mangle that URL as well, I suggest that you use
http://groups.google.com/advanced_group_search, and search for the
exact phrase "between the GROUP BY and ORDER BY". There you can see
what Steve really said.


Jul 20 '05 #9

I haven't been able to resolve this probelm.
My guess is that columns in you select statement can not be supressed in
the result.

I'm I right?

Rgds,

--
Posted via http://dbforums.com
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
I'm creating a simple reply form, and if a form item isn't answered I get an error: "Notice: Undefined index: rb_amntspent in c:\inetpub\wwwroot\mackinaw\survey.php on line 36" even if in the...
1
by: roderik | last post by:
How do I supress the output generated from each psycopg command: >>> import psycopg initpsycopg: initializing psycopg 1.99.10 typecast_init: initializing NUMBER .. .. microprotocols_add:...
1
by: David | last post by:
I have a custom control that contains a class that Inherits the panel control. I am trying to catch a keydown event in this class and then supress it from the rest of the control as well as the...
3
by: JG | last post by:
Hi all, I have a simple aspx page. On the page there is only one button. When I click on the button, the event sequence is Page_Load, Button1_click and Page_PreRender. How do I supress the...
2
by: Still Learning | last post by:
Hi, Currently a crystal report is getting 359.9999 from a dataset. Even with rounding set to 0.0001 it displays 360.0 which is wrong. How can I supress rounding or get it to display 359.9999? ...
4
by: rob c | last post by:
This is a minor thing and only appears in IE (so far), but I'd like to know to correct it (if possible). Whenever I use a form on a webpage, Explorer always leaves a blank line following the...
1
by: Nikhil Mittal | last post by:
How to supress system errors in windows perl In unix it is 2>&1 , what is in windows :o
2
by: =?Utf-8?B?Q2hyaXMgRGF2b2xp?= | last post by:
I have to zero supress some numbers ie; 20.000000000 or 20.0100000 What is an easy way to do this? If I got to write code, is there some code examples out there? -- Chris Davoli
2
by: khani | last post by:
Hi i have following situation in cystal report in detail section i have a field say name.now i have five duplication record like this zahid zahid zahid zahid
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.