× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I've using a sql case statement to sum up measurements.
This is working fine, except now I would like to add an ELSE clause and I can seem to get it to work.

As a note(in case it matters) The below code is copied from SQL Server where I'm testing the original sql statement, but in actuality the code will be run from RPG using Scott's JDBCR4

Below is an excerpt from the sql statement that works.

select
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 1
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_1' ,
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 2
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_2' ,
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 3
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_3'
FROM MAINSVW

I want something like this, but can't make it work.

select
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 1
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_1' ,
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 2
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_2' ,
sum(case
when maintype <> 'Transmission '
and Diameter <= 2 and Material = 3
and (inServiceDate < '2014-11-01' OR InServiceDate IS Null)
then measuredlength end) as
'P2_3'

ELSE
sum measuredlength as 'unknown'

FROM MAINSVW

Thanks

Mike
NOTICE: This message, including any attachment, is intended as a confidential and privileged communication. If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this message.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.