|
Thanks for your reply Chuck
I tried the following
SELECT OPER,
case BOX_SIZE when '1'then SEL0003 end as Count1, case BOX_SIZE when
'2'then SEL0003 end as Count2, case BOX_SIZE when '3'then SEL0003 end
as Count3, case BOX_SIZE when '4'then SEL0003 end as Count4, case
BOX_SIZE when '5'then SEL0003 end as Count5, case BOX_SIZE when
'6'then SEL0003 end as Count6, case BOX_SIZE when '7'then SEL0003 end
as Count7, case BOX_SIZE when '8'then SEL0003 end as Count8, case
BOX_SIZE when '9'then SEL0003 end as Count9, case BOX_SIZE when
'0'then SEL0003 end as Count0, case BOX_SIZE when not between '0' and
'9' then
SEL0003 end as Count_Other FROM ORDSPCKEDZ
And received the error
Keyword BETWEEN not expected. Valid tokens: + - THEN.
Alan Shore
E-mail : ASHORE@xxxxxxxx
Phone [O] : (631) 200-5019
Phone [C] : (631) 880-8640
'If you're going through hell, keep going.'
Winston Churchill
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of
CRPence
Sent: Thursday, June 11, 2015 10:44 AM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: How to use SQL CASE
On 11-Jun-2015 07:31 -0600, Alan Shore wrote:
Before I forget - we are on V5r4 - hopefully moving up to the latestApparently: OPER
release very soon.
Here is my predicament:
I have a file that contains 3 fields
* User Profile name
* Box SizeApparently: BOX_SIZE
* CountApparently: SEL0003
Box size can have valid values of:
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
I want to create a new file with the following
So apparently either the SELECT in a CREATE TABLE or CREATE VIEW.?
SELECT OPER,
case BOX_SIZE when '1'then SEL0003 end as Count1,
case BOX_SIZE when '2'then SEL0003 end as Count2,
case BOX_SIZE when '3'then SEL0003 end as Count3,
case BOX_SIZE when '4'then SEL0003 end as Count4,
case BOX_SIZE when '5'then SEL0003 end as Count5,
case BOX_SIZE when '6'then SEL0003 end as Count6,
case BOX_SIZE when '7'then SEL0003 end as Count7,
case BOX_SIZE when '8'then SEL0003 end as Count8,
case BOX_SIZE when '9'then SEL0003 end as Count9,
case BOX_SIZE when '0'then SEL0003 end as Count0,
case BOX_SIZE when not in ('0', '1', '2', '3', '4',
'5', '6', '7''8', '9',) then
SEL0003 end as Count_Other
FROM file
It's the last case clause that I am having a problem with
case BOX_SIZE when not in ('0', '1', '2', '3', '4',
'5', '6', '7''8', '9',) then
SEL0003 end as Count_Other
Other than the missing comma and the extraneous comma? Define "problem"? If just those two problems, then try the following revision for resolution:
case BOX_SIZE when not in ('0', '1', '2', '3', '4',
'5', '6', '7', '8', '9') then
SEL0003 end as Count_Other
IIRC the BETWEEN predicate is inclusive, so assuming any /normal/ Sort Sequence (SRTSEQ) [other than a custom table (TBL)], then the following is an alternative:
case BOX_SIZE when not between '0' and '9' then
SEL0003 end as Count_Other
I want to capture the count if it's not a valid value into its own
field
I hope this makes sense
As always - all response gratefully accepted
HTH
--
Regards, Chuck
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.
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.