469,281 Members | 2,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

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 2480

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by roderik | last post: by
1 post views Thread by David | last post: by
2 posts views Thread by Still Learning | last post: by
2 posts views Thread by =?Utf-8?B?Q2hyaXMgRGF2b2xp?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.