I have a spotfire dashboard with two dropdown lists, one for Day and one for Month, that I want to use to limit the data of visualizations.
I need to be able to use both filters at the same time. I currently have a case statement written out to do this however case statements by default stop evaluating expressions when they reach a true statement.
For example below, I have the statements for the MonthSelector on top, it does not continue to evaluate past that to the DaySelector.
case
when "${MonthSelector}"="all" then [Month] <> ''
when "${MonthSelector}"<>"all" then [Month] = "${MonthSelector}"
when "${DaySelector}"="all" then [Week_Day] <> ''
when "${DaySelector}"="WeekDay" then [Week_Day] <> 'Saturday' and [Week_Day] <> 'Sunday'
when "${DaySelector}"="WeekEnd" then [Week_Day] = 'Saturday' OR [Week_Day] = 'Sunday'
when "${DaySelector}"<>"WeekEnd" AND "${DaySelector}"<>"WeekDay" AND "${DaySelector}"<>"all" then [Week_Day] = "${DaySelector}"
else false end case
I need assistance in either somehow getting spotfire to continue evaluating the case statement past the first true, or another way of writing a data limiting expression that will limit data based on both dropdowns.
I am at a loss, any help will be appreciated.
Can you try nesting the cases? Maybe like this untested expression:
case
when "${MonthSelector}"="all" then case
when "${DaySelector}"="all" then [Week_Day] <> '' and [Month] <> ''
when "${DaySelector}"="WeekDay" then [Week_Day] <> 'Saturday' and [Week_Day] <> 'Sunday' and [Month] <> ''
when "${DaySelector}"="WeekEnd" then [Week_Day] = 'Saturday' OR [Week_Day] = 'Sunday' and [Month] <> ''
when "${DaySelector}"<>"WeekEnd" AND "${DaySelector}"<>"WeekDay" AND "${DaySelector}"<>"all" then [Week_Day] = "${DaySelector}" and [Month] <> ''
else false
end
when "${MonthSelector}"<>"all" then case
when "${DaySelector}"="all" then [Week_Day] <> '' and [Month] = "${MonthSelector}"
when "${DaySelector}"="WeekDay" then [Week_Day] <> 'Saturday' and [Week_Day] <> 'Sunday' and [Month] = "${MonthSelector}"
when "${DaySelector}"="WeekEnd" then [Week_Day] = 'Saturday' OR [Week_Day] = 'Sunday' and [Month] = "${MonthSelector}"
when "${DaySelector}"<>"WeekEnd" AND "${DaySelector}"<>"WeekDay" AND "${DaySelector}"<>"all" then [Week_Day] = "${DaySelector}" and [Month] = "${MonthSelector}"
else false
end
else false
end
Related
I have logic which i need to convert it to decode statement
My logic is below :
if emptr =='SBCS':
empcd=empvar
else:
if empcal <> depcal and empid in ('SSC','HSC'):
empcd = (emp_sal/avgsal) * empad
elif empcal <> depcal and empid not in ('SSC','HSC'):
empcd = emp_del
else:
empcd = emp_dev
Tried myself to write the logic in expression
IIF ( emptr ='SBCS' , empvar , IIF(empcal <> depcal,IIF(empcal <> depcal and empid in ('SSC','HSC'),(emp_sal/avgsal) * empad,emp_del),emp_dev))
I have written DECODE logic , but not sure right or wrong
DECODE(TRUE,
empid ='SBCS', empvar,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and (empid <> 'SSC' or empid <> 'HSC'), emp_del,
emp_dev
)
Feel free to share your logic if the DECODE logic is not right
You can refer to below expression. Pls remove comments (--comments) if needed.
iif (emptr ='SBCS', empvar,
iif( -- first else if part
empcal <> depcal and IN (empid, 'SSC','HSC'), (emp_sal/avgsal) * empad,
iif ( --second elif
empcal <> depcal and NOT IN (empid, 'SSC','HSC') , emp_del,
emp_dev -- last else
)
)
)
I can see your expression and can see some issue with 3rd or condition. in case of NOT IN, or doesnt work. I changed your decode so you can use code below but pls check it before using it.
DECODE(TRUE,
empid ='SBCS', empvar,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and (empid <> 'SSC' and empid <> 'HSC'), emp_del,
emp_dev
)
I believe I've already answered this exact question there. Was there anything wrong with the below code I provided?
DECODE(TRUE,
empid ='SBCS', v_employee_code_number,
empcal <> depcal and (empid = 'SSC' or empid = 'HSC'), (emp_sal/avgsal) * empad,
empcal <> depcal and empid <> 'SSC' and empid <> 'HSC', emp_del,
emp_dev
)
My select query before changes was:
select * from abc
WHERE
CASE WHEN NVL(gr.Rgid,a.pc) = 'CRA' THEN
CASE WHEN NVL(TRUNC(a.DATEOFSFROM),TO_DATE('99991231','YYYYMMDD')) >= TO_DATE('20170101','YYYYMMDD') THEN 'Y' ELSE 'N' END
When gr.Rgid='021SHOP' THEN
CASE WHEN TRUNC(a.datep) <= to_date('20190630', 'YYYYMMDD') then 'Y' ELSE 'N' end
ELSE 'Y' END = 'Y'
I need new case when statement,so I added:
select * from abc
WHERE
CASE WHEN NVL(gr.Rgid,a.pc) = 'CRA' THEN
CASE WHEN NVL(TRUNC(a.DATEOFSFROM),TO_DATE('99991231','YYYYMMDD')) >= TO_DATE('20170101','YYYYMMDD') THEN 'Y' ELSE 'N' END
When gr.Rgid='021SHOP' THEN
CASE WHEN TRUNC(a.datep) <= to_date('20190630', 'YYYYMMDD') then 'Y' ELSE 'N' end
ELSE 'Y' END = 'Y'
CASE WHEN NVL(gr.Rgid,a.pc) IN ('01FLW','002FE') then
a.datep <=to_date('20180131', 'YYYYMMDD') END;
I added these statement from my side
CASE WHEN NVL(gr.Rgid,a.pc) IN ('01FLW','002FE') then
a.datep <=to_date('20180131', 'YYYYMMDD') END;
But I am getting error:ORA-00905:missing keyword error. I searched these similar question but I only see is case when used is being wrong.But from my analysis,the case when I am using in right.
You didn't say what exactly should be the outcome so I guessed. Note comments within code, which contains new CASE:
SELECT *
FROM abc
WHERE CASE
WHEN NVL (gr.Rgid, a.pc) = 'CRA'
THEN
CASE
WHEN NVL (TRUNC (a.DATEOFSFROM),
TO_DATE ('99991231', 'YYYYMMDD')) >=
TO_DATE ('20170101', 'YYYYMMDD')
THEN
'Y'
ELSE
'N'
END
WHEN gr.Rgid = '021SHOP'
THEN
CASE
WHEN TRUNC (a.datep) <= TO_DATE ('20190630', 'YYYYMMDD')
THEN
'Y'
ELSE
'N'
END
-- your new WHEN begins here ...
WHEN NVL (gr.Rgid, a.pc) IN ('01FLW', '002FE')
THEN
CASE
WHEN a.datep <= TO_DATE ('20180131', 'YYYYMMDD')
THEN 'Y'
ELSE 'N'
END
-- ... and ends here
ELSE
'Y'
END =
'Y'
Your query:
select * from abc
WHERE
CASE WHEN NVL(gr.Rgid,a.pc) = 'CRA' THEN
CASE WHEN NVL(TRUNC(a.DATEOFSFROM),TO_DATE('99991231','YYYYMMDD')) >= TO_DATE('20170101','YYYYMMDD') THEN 'Y' ELSE 'N' END
When gr.Rgid='021SHOP' THEN
CASE WHEN TRUNC(a.datep) <= to_date('20190630', 'YYYYMMDD') then 'Y' ELSE 'N' end
ELSE 'Y' END = 'Y'
that's all ok.
When adding CASE WHEN NVL(gr.Rgid,a.pc) IN ('01FLW','002FE') then a.datep <=to_date('20180131', 'YYYYMMDD') END to the end you're screwing up the syntax.
Syntax: where a = b or c = d.
You wrote where a = b and then added c so it becomes where a = b c.
Add your new line with a AND or OR and get a value to compare it to, like
SELECT * FROM ABC
WHERE
CASE WHEN NVL(gr.Rgid,a.pc) = 'CRA' THEN
...
ELSE 'Y' END = 'Y'
-- new here
AND CASE WHEN NVL(gr.Rgid,a.pc) IN ('01FLW','002FE') AND a.datep <=to_date('20180131', 'YYYYMMDD')
then 'true'
ELSE 'false'
END = 'true';
I also transformed your case statement to a equation like a = b by moving your condition into the WHEN-Block and then comparing if it's the first when block or not by ... END = 'true'.
You cannot add where statements within a case expression like you did.
Please note that I wrote this without actual verification, so syntac errors may still occur.
I have a query below:
declare #max int
select #max = max(len(RPVINVNoSpace)) from jde_SupplierInvoices
update jde_SupplierInvoices set RPVINVNumeric = ''
declare #loop int = 1
while #loop <= #max
begin
update jde_SupplierInvoices set RPVINVNumeric = RPVINVNumeric +
case when substring(RPVINVNoSpace,#loop,1) in ('0','1','2','3','4','5','6','7','8','9')
then substring(RPVINVNoSpace,#loop,1)
when substring(lower(RPVINVNoSpace),#loop,3) = 'jan' then '01'
when substring(lower(RPVINVNoSpace),#loop,3) = 'feb' then '02'
when substring(lower(RPVINVNoSpace),#loop,3) = 'mar' then '03'
when substring(lower(RPVINVNoSpace),#loop,3) = 'apr' then '04'
when substring(lower(RPVINVNoSpace),#loop,3) = 'may' then '05'
when substring(lower(RPVINVNoSpace),#loop,3) = 'jun' then '06'
when substring(lower(RPVINVNoSpace),#loop,3) = 'jul' then '07'
when substring(lower(RPVINVNoSpace),#loop,3) = 'aug' then '08'
when substring(lower(RPVINVNoSpace),#loop,3) = 'sep' then '09'
when substring(lower(RPVINVNoSpace),#loop,3) = 'oct' then '10'
when substring(lower(RPVINVNoSpace),#loop,3) = 'nov' then '11'
when substring(lower(RPVINVNoSpace),#loop,3) = 'dec' then '12'
else ''
end
set #loop = #loop + 1
end
The challenge is to come up with a better way to re-implement this and no CLR allowed.Basically this query is updating the column value(RPVINVNumeric) to numeric derived from another column(RPVINVNoSpace) which consist of alphanumeric characters.
The table has millions of rows and the script takes nearly 4 mins to run.
Here is the sample data for reference:
data sample image
I am not able to format the data screenshot further apologies for that.
Any help will be much appreciated.
Thanks,
Arti
I need to update the the following columns in a table. males,females,infants and children using SQL procedure.from this column paxtype which has f,i,m,c.which is females,infants,males and children repectively.but am not able error ORA-00907: missing right parenthesis
update xxxx a set (a.INFANTS,a.MALES,a.CHILDREN,a.FEMALES)=
(SELECT b.PAXTYPE, COUNT (b.PAXTYPE) FROM xxxx b
(case ( count (b.PAXTYPE))
when ( count (b.PAXTYPE))='M'then 'a.males'
when ( count (b.PAXTYPE))='F' then 'a.females'
when ( count (b.PAXTYPE))='I' then 'a.infants'
when ( count (b.PAXTYPE))='C' then 'a.children'
END)
WHERE a.date_key = TO_CHAR (b.FLIGHTDATE, 'RRRRMMDD')
AND a.FLTNUM_KEY = TRIM (SUBSTR (b.flightnumber, 3))
AND a.origin = b.frm
AND a.destination = b.too
--and a.date_key=20170801
--and fightnumber = '100'
AND TRIM (a.cancelled) IS NULL
-- and rownum = 1
GROUP BY b.PAXTYPE;
)
It looks like you want a total count of each type, right? I think this is what you want to do.
update xxxx a set (a.INFANTS,a.MALES,a.CHILDREN,a.FEMALES)=
(SELECT
sum(case when b.PAXTYPE = 'I' then 1 else 0 end) as infants_count,
sum(case when b.PAXTYPE = 'M' then 1 else 0 end) as males_count,
sum(case when b.PAXTYPE = 'C' then 1 else 0 end) as children_count,
sum(case when b.PAXTYPE = 'F' then 1 else 0 end) as females_count
FROM xxxx b
WHERE a.date_key = TO_CHAR (b.FLIGHTDATE, 'RRRRMMDD')
AND a.FLTNUM_KEY = TRIM (SUBSTR (b.flightnumber, 3))
AND a.origin = b.frm
AND a.destination = b.too
--and a.date_key=20170801
--and fightnumber = '100'
AND TRIM (a.cancelled) IS NULL
-- and rownum = 1
GROUP BY b.PAXTYPE);
Pseudocode to describe what I'm looking at:
SELECT
COLUMN_A
, COLUMN_B
, CASE WHEN (OUTER_CONDITION_A = TRUE) THEN
CASE WHEN (INNER_CONDITION_1 = TRUE) THEN 'Choice 1'
WHEN (INNER_CONDITION_2 = TRUE) THEN 'Choice 2'
WHEN (INNER_CONDITION_3 = TRUE) THEN 'Choice 3'
ELSE 'Other Choice' END
ELSE CASE WHEN (OUTER_CONDITION_B = TRUE) THEN
CASE WHEN (INNER_CONDITION_4 = TRUE) THEN 'Choice 4'
WHEN (INNER_CONDITION_5 = TRUE) THEN 'Choice 5'
WHEN (INNER_CONDITION_6 = TRUE) THEN 'Choice 6'
ELSE TO_CHAR(MAX(DATE)) END
END AS 'COLUMN_C'
, COLUMN_D
FROM TABLE_A
Oracle SQL Developer is telling me that I need to add a GROUP BY clause:
GROUP BY
COLUMN_A
, COLUMN_B
, COLUMN_D
When I try to run this, I get an ORA-00979 (not a GROUP BY expression) error. I'm stumped here.
You are using an aggregate function MAX(DATE) in the case statement along with other columns without any group by clause.
Assuming, you want to get the overall max date in each row, you can use analytic MAX(DATE) OVER ():
SELECT
COLUMN_A
, COLUMN_B
, CASE WHEN (OUTER_CONDITION_A = TRUE) THEN
CASE WHEN (INNER_CONDITION_1 = TRUE) THEN 'Choice 1'
WHEN (INNER_CONDITION_2 = TRUE) THEN 'Choice 2'
WHEN (INNER_CONDITION_3 = TRUE) THEN 'Choice 3'
ELSE 'Other Choice' END
ELSE CASE WHEN (OUTER_CONDITION_B = TRUE) THEN
CASE WHEN (INNER_CONDITION_4 = TRUE) THEN 'Choice 4'
WHEN (INNER_CONDITION_5 = TRUE) THEN 'Choice 5'
WHEN (INNER_CONDITION_6 = TRUE) THEN 'Choice 6'
ELSE TO_CHAR(MAX(DATE) OVER ()) END
END AS 'COLUMN_C'
, COLUMN_D
FROM TABLE_A