Case When Like
i tried using the following below as a column in an answer report, but it didnt give me the right result, can you use the LIKE operator in a Case When statement?
CASE WHEN column1 LIKE 'MBD*' THEN 'MBD' ELSE 'NA' END
may be it is case sensitive. try:
CASE WHEN upper(column1) LIKE 'MBD*' THEN 'MBD' ELSE 'NA' END
or
CASE WHEN left(upper(ltrim(column1)), 3) = 'MBD' THEN 'MBD' ELSE 'NA' END
Similar Messages
-
Using CASE WHEN for Essbase column in OBIEE 11g
Hi all,
I have a business model in OBIEE 11g, taking the source from Essbase 11. The measures of the Essbase cube in the physical layer is flattened, and the aggregations for the measures are set to SUM.
The Product dimension has 5 generations. In Product logical table, I created a logical column called "Product Grouping" using a simple CASE WHEN formula:
CASE
WHEN "TEST"."Product"."Gen5,Product" IN ('100-10', '100-20', '200-10', '300-10') THEN 'Group 1'
WHEN "TEST"."Product"."Gen5,Product" IN ('100-30', '200-20') THEN 'Group 2'
ELSE 'Group 3'
END
Problems:
1. If I don't place this "Product Grouping" in the logical level/hierarchy, I got error in the report when I simply show Product Grouping and a measure.
2. If I place this "Product Grouping" in the logical level/hierarchy (on the 5th level), no more error in the report when I simply show "Product Grouping" and a measure. The measure value also shows the correct SUM (group by). However, when I add "Gen1,Product" the "Product Grouping" and the measure value suddenly becomes not grouped by.
Has anyone ever tried and encountered something like this? Any thoughts?
Thank you very much!Hi Deepak, thansk for the suggestion.
However, I can't use calculated item for this report because:
1. incorrect result will be shown when my measures involve a formula to derive a percentage value.
2. calculated item is not available if we do "combine requests" (or union) in 11g.
Any thoughts anyone on how to solve this? Is this just me, or it's a bug?
Thank you very much. -
Using case when to an aggregate function
Hi,
I have a sql statement like below,
Select CASE WHEN (Sum(Amount) Over (Partition By Name),1,1) = '-' THEN 0 ELSE Sum(Amount) Over (Partition By Name) END AS Amount_Person
From tbPerson
But when I run the sql statement above I got error ORA-00920: invalid relational operator. What I'm trying to do is when the total amount for each person is negative then it will return 0 else it will return the positive value. I dont want to use the GROUP BY function. Is there any other way than using the Sum Over function? ThanksLike this?
SELECT CASE WHEN Sum(Amount) Over (Partition By Name) < 0 THEN 0
ELSE Sum(Amount) Over (Partition By Name)
END AS Amount_Person
FROM tbPerson
;or using GREATEST function :
SELECT GREATEST(
Sum(Amount) Over (Partition By Name)
, 0
) as Amount_Person
FROM tbPerson
;Edited by: odie_63 on 24 févr. 2011 09:12 -
Using CASE WHEN in PL/SQL package
I am trying to convert the values in a selected column into 1 and 0 so that I can display all 1s in one column, all 0s in another. I am doing this in a PL/SQL package. However ORACLE compiler does not like the CASE construct.
Does anyone know how to group values in a column into several new columns. If CASE WHEN construct is not doable in PL/SQL, what alternatives are there? Thanks.
/******* My package starts here *******/
CREATE OR REPLACE PACKAGE TEST_NEED AS
PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2);
END CVRR_MON_NEED;
CREATE OR REPLACE PACKAGE BODY TEST_NEED
AS
PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2)
IS
TEST_START DATE := TO_DATE(STARTING_DATE,'MM/DD/YYYY');
CURSOR v_Cursor IS
SELECT A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID,
SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 > 40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND B.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0 END) QUALIFIED
FROM A, B, C, D
WHERE A.ID = B.B_ID
AND RTRIM(A.P_CODE) = C.P_CODE
AND A.P_ID = D.P_ID
AND A.P_ID < 99999999999999999999
AND A.E_DATETIME < SYSDATE
GROUP BY A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID;
v_RecordHolder v_Cursor%ROWTYPE;
BEGIN
OPEN v_Cursor;
FETCH v_CursorINTO v_RecordHolder ;
WHILE v_Cursor%FOUND LOOP
look for records in another table with matching keys of the cursor
if found then update by incrementing the existing values in the matching records with values of the current currsor row
else insert the current cursor row
FETCH v_Cursor INTO v_RecordHolder ;
END LOOP;
END procTEST_NEED;
END TEST_NEED;I am trying to convert the values in a selected
column into 1 and 0 so that I can display all 1s in
one column, all 0s in another. I am doing this in a
PL/SQL package. However ORACLE compiler does not
like the CASE construct.
Does anyone know how to group values in a column into
several new columns. If CASE WHEN construct is not
doable in PL/SQL, what alternatives are there?
Thanks.
CURSOR v_Cursor IS
SELECT A.D_CODE, A.M_CODE, TEST_START ,
, C.C_NAME,C.P_ID,
SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 ANDB.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0
END) QUALIFIEDUse the Decode function. This has been around in oracle SQL for ages and works like a case construct.
You would do something like
select ...
sum( decode (MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND
B.B_CODE IN ('11.1','222.2','272.4') 1,0 ) -
Using :case when in where clause
Hello,
I need some help with using of case statement in a where clause
Table that contains info about employees taking some coursework:
Class (values could be SAP, ORACLE, JAVA)
Code (if Class is SAP then CODE is not null; if class is any other CODE is NULL)
Start Date (date they began class not null)
End Date (date then ended the class - could be null)
Employee Level(numbers from one through five)
I need a single LOV in forms that should show Employee_Level for input class,code,date.
How to do this?
I started off with this but get 'missing statement error'
select distinct employee_level from e_course
where (
case when &class='SAP' then code ='1' and start_date > to_date('20000101','YYYYMMDD') and
end_date < to_date('20000101','YYYYMMDD')
else
null
end) order by employee_level;ThanksHi,
user469956 wrote:
But all these examples have only one condition for each case.Depending on how you count, all WHERE clauses have only one condition.
I see an example in that thread that has 6 atomic conditions, linked by AND and OR.
I need to check date & code. This is what is causing the error.Why do you want to use a CASE statement?
Why can't you put all your conditions directly iinto a WHERE clause, soemthing like this:
WHERE ( &class='SAP'
AND code ='1'
OR ( start_date > to_date('20000101','YYYYMMDD')
AND end_date < to_date('20000101','YYYYMMDD')
)I said "something like this" because I don't know what you really want to do. -
SELECT v_startdate, v_enddate,
(CASE WHEN SYSDATE BETWEEN v_startdate AND v_enddate THEN
‘active’
ELSE
‘inactive’
END) status
FROM correction_tab;
Could you kindly guide us as to how can we use DECODE and get the desired output.
Thanks,
Rami Reddy.You can, like this.
However, the CASE seems a lot clearer to me so why bother with a DECODE?
sql> with correction_tab as
2 ( select trunc(sysdate)-1 as v_startdate, trunc(sysdate) as v_enddate from dual
3 union all
4 select trunc(sysdate) as v_startdate, trunc(sysdate)+1 as v_enddate from dual
5 union all
6 select trunc(sysdate)+1 as v_startdate, trunc(sysdate)+2 as v_enddate from dual
7 )
8 SELECT v_startdate
9 , v_enddate
10 , CASE
11 WHEN SYSDATE BETWEEN v_startdate AND v_enddate
12 THEN 'active'
13 ELSE 'inactive'
14 END status
15 , decode ( sign(sysdate-v_startdate), 1, decode(sign(v_enddate-sysdate), 1, 'active', 'inactive'), 'inactive')
as status2
16 FROM correction_tab
17 /
V_STARTDA V_ENDDATE STATUS STATUS2
12-DEC-12 13-DEC-12 inactive inactive
13-DEC-12 14-DEC-12 active active
14-DEC-12 15-DEC-12 inactive inactive -
Using case when statement or decode stament in where clause
hi gems..
i have a problem in the following query..
i am trying to use case when statement in the where clause of a select query.
select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
cr.salary as salary
from customer_details cr
where (case when '>' = '>' then 'cr.salary > 5000'
when '>' = '<' then 'cr.salary < 5000'
when '>' = '=' then 'cr.salary = 5000'
else null
end);
the expression in the when clause of the case-when statement will come from UI and depending on the choice i need to make the where clause.
thats why for running the query, i have put '>' in that place.
so the original query will look like this(for your reference):
select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
cr.salary as salary
from customer_details cr
where (case when variable = '>' then 'cr.salary > 5000'
when variable = '<' then 'cr.salary < 5000'
when variable = '=' then 'cr.salary = 5000'
else null
end);
so, in actual case,if the user selects '>' then the filter will be "where cr.salary > 5000"
if the user selects '<' then the filter will be "where cr.salary < 5000"
if the user selects '=' then the filter will be "where cr.salary = 5000"
but i am getting the error "ORA 00920:invalid relational operator"
please help..thanks in advance..Hi,
select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
cr.salary as salary
from customer_details cr
where ( v_variable = 'bigger'
and cr.salary > 5000
or ( v_variable = 'less'
and cr.salary < 5000
or ( v_variable = 'eq'
and cr.salary = 5000
)Edited by: user6806750 on 22.12.2011 14:56
For some reason I can't write in sql '<', '>', '=' -
Hi all!
I have a report in Discoverer Plus (Version 10.1.2.48.18) which contains 2 columns: One with actual spendings and one with budget figures. I want to make a third column which holds actual spendings in percentage of the budget. To do this, I need to make a calculation similar to:
CASE WHEN SUM(budget) <> 0 THEN SUM(spendings)/SUM(budget) ELSE NULL END
However, when I apply this calculation to the third column, my report don't return any numbers at all in any column.
What am I doing wrong? -- Is this a bug, and how should I solve my problem?
~MortenI can get something out if I do this (applying an aggregate function to it all):
SUM(CASE WHEN budget <> 0 THEN spendings/budget ELSE NULL END)
However, this is wrong (Summarizing these percentages doesn't give any meaning).
SQL lookes something like this:
SELECT /*+ NOREWRITE */ o100448.ACCOUNT as E100451,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) as E101004,MAX(o100448.ACCOUNTNUM) as as100473_100451_NEW,CASE WHEN ( SUM(o100862.BUDGET) ) <> 0 THEN ( SUM(o100862.AMOUNT) )/( SUM(o100862.BUDGET) ) ELSE NULL END as C_1,( SUM(o100862.BUDGET) )*o100448.SIGN as C_3,( SUM(o100862.AMOUNT) )*o100448.SIGN as C_2,GROUPING_ID(o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM')))) as GID
FROM TANGO.TANGO_ACCOUNTS o100448,
TANGO.TANGO_SUMS o100862
WHERE ( (o100862.ORG = o100448.ORG AND o100862.ACCOUNTNUM = o100448.SUBACCOUNTNUM))
AND (o100448.ACCOUNTNUM BETWEEN 30000 AND 79999)
AND (o100862.DIM = '50')
AND (o100448.ORG = 'bru')
GROUP BY GROUPING SETS(( o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ),( o100448.ACCOUNT,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ))
HAVING (GROUP_ID()=0)
ORDER BY GID DESC;
I tried to fire this SQL up in TOAD (or whatever SQL-tool you might have), and columns C_2 and C_3 are empty. Seems like I'm doing something awfully wrong here.....
Any ideas? (There must be some SQL sharks out there ;-p)
~Morten -
How to use case when statements in ODI
I need to put conditional logic before DVM look up in ODI. In the expression editor I put the following statement:-
CASE WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS' THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=EBIZ_CELL.CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC' THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=EBIZ_CELL.CELL_DATA
END
It did not work,
Under Operators ->All Executions, found the error:-
905 : 42000 : java.sql.SQLException: ORA-00905: missing keyword
The description in Session Task contained:-
select
C1_JOURNAL_TEMPL
from APPS.POC_JOURNAL_TEMP_SOURCE_TBL POC_JOURNAL_TEMP_SOURCE_TBL, APPS.C$_0POC_JOURNAL_TEMP_TARGET_TB
where
(1=1)
And (CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=C2_CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=C2_CELL_DATA
END)
Checked the above code in PL/SQL Developer but it gave errors.
In PL/SQL developer tried to check a simple query using case-when but even that is giving errors in the case-when portion.
The query is as follows:-
select phase_code, accounting_period, sum(eff_cc) as BD_Eff_QTD
from prj_detail
where
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'
then
1
when 'RAC'
then
2
when 'XXX'
then
3
else
end
I would like to know what is wrong with the above code.
Please let me know what is the correct way of using case-when in PL/SQL as well as in ODI.Your ODI case statement and PL/SQL Case statement both looks confusing.
You are writing case statement under where clause which is not a good practise. If you want to implement logic like-
select a,b,c from <table>
where
when cond^n^ 1 then do 1
when cond^n^ 2 then do 2
then better you seperate your query for each filter and do a union, in other words-
select a,b,c from <table>
where cond^n^ 1
union
select a,b,c from <table>
where cond^n^ 2
If you are writing case staement to retrieve a value/column (EBIZ_CELL.CELL_DATA) then no need to include it under filter.
ODI case for column EBIZ_CELL.CELL_DATA will be:
CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)
END
Pl/SQL query-
select phase_code, accounting_period,
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'then 1
when 'RAC' then 2
when 'XXX' then 3
else 'default value' --- (if no else needed then can also remove else part)
end,
sum(eff_cc) as BD_Eff_QTD
from prj_detail
Suggested as per what is understood, hope it helps.
Edited by: 939451 on Jul 5, 2012 12:47 AM
Edited by: 939451 on Jul 5, 2012 12:48 AM -
Issue with case when try to modify the siimple query
Hello PL/SQL Gurus/Experts,
I am stuck with an issue (could be simple) but not gettings any headsway -
select 365/day_num_yr Anul_Fact from Date where date_dt = trunc(sysdate -1) value returns is as - 1.46
need to write this in the form of case (as i need to multiply this to some other outer query), i want to store it ina variable and and then use the same in outer one -
but when use the following then it is always returning the value as 0 and not the same output as returned by the above query without case.
select (case when date_dt =trunc(sysdate -1) then 365/day_num_yr else 0 END) Anul_Fact Kindly help, i appericate your time and effort in advance.Thanks for providing the Drop table and CTAS script. It eased the job of creating sample data;
I only used few data from the table:
drop table T4;
create table T4(day_num_yr, date_dt) as
select 249, to_date('09/05/2012', 'MM/DD/YYYY') from dual union all
select 250, to_date('09/06/2012', 'MM/DD/YYYY') from dual union all
select 251, to_date('09/07/2012', 'MM/DD/YYYY') from dual union all
select 252, to_date('09/08/2012', 'MM/DD/YYYY') from dual;
select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,
case when date_dt = trunc(sysdate - 1) then 365 / day_num_yr
else 0
end num_day
from t4;
DATE_DT PREV_DT TRUNC_PREV_DT NUM_DAY
05-SEP-12 06-SEP-12 06-SEP-12 0
06-SEP-12 06-SEP-12 06-SEP-12 1.46
07-SEP-12 06-SEP-12 06-SEP-12 0
08-SEP-12 06-SEP-12 06-SEP-12 0See the output. For Date_DT as 6-Sep, i.e. a Day before Today, we are getting the Output, but for other dates we are not.
One another suggestion I would like to make is, (assuming) you are using the Table only for storing the Current day of Year and not including Public Holidays etc. then you can use a 'DDD' format model to get the Current Day of year starting 1 Jan.
Something like below:
select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,
case when date_dt = trunc(sysdate - 1) then 365 / to_char(date_dt, 'DDD')
else 0
end num_day
from t4; -
Returne between dates in case when
i want to return between dates values on case when clauses on where clauses
like
and
(case
when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
end) h.default_effective_date
the problem is in the = operator but i don't know haw to use this
any help??ok here is the full coad
select
DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY')branch_nature,
decode(cc.segment1,'A6260','Head Office','Branches') branch_type,
cc.segment1,
decode (h.currency_code,'EGP','mahly','agnaby') currency_code ,
cc.segment3,
t.description,
CASE
when h.currency_code in('EGP') then sum(l.entered_cr)
else 0
end entered_cr,--sum(l.entered_cr) entered_cr,
CASE
when h.currency_code in('EGP') then sum(l.entered_dr)
else 0
end entered_dr, --sum(l.entered_dr) entered_dr,
CASE
when h.currency_code NOT in('EGP') then sum(l.accounted_cr)
else 0
end accounted_Dr,--0 accounted_Dr,
CASE
when h.currency_code NOT in('EGP') then sum(l.accounted_dr)
else 0
end accounted_cr --0 accounted_cr
from apps.gl_je_headers h,
apps.gl_je_lines L,
apps.gl_code_combinations cc,
apps.fnd_flex_values_tl t ,
applsys.fnd_user us,
apps.gl_je_batches b
where h.status = 'P'
and us.user_id = h.Created_by
--and h.currency_code in('EGP')
and l.je_header_id = h.je_header_id
and l.code_combination_id =cc.code_combination_id
and cc.segment3 = t.flex_value_meaning
and cc.segment3 in ('31000020','40505020')
and cc.segment1 in ('A5550','B0010')
-- and (DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY') =:P_branch_nature OR :P_branch_nature is NULL)
--and (decode(cc.segment1,'A6260','Head Office','Branches') = :P_BRANCH_TYPE OR :P_BRANCH_TYPE is NULL)
and t.description is not null
and t.language ='AR'
and h.je_batch_id = b.je_batch_id
and
(case
when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
then (between to_date(:P_Start_date,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (between to_date(:P_Start_date2,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
end) h.default_effective_date
and (case
when (cc.segment3 like '4%' or cc.segment3 like '5%')
then (h.default_effective_date)
end) between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr')*/
group by cc.segment3 , t.description , cc.segment1,h.currency_code;
the part between tages need to modigied -
Problem with case when statement, when doing an insert.
Hi there, I have written the following coding, that has got an issue, due to not being allowed null values to be inserted into a column on a table.
,Case
WHENCL.LocationISNOTNULLANDCL.[Floor]ISNOTNULLANDCL.RoomISNULLTHEN
(SELECTTop1
FL.FloorIDFROMPMIS.dbo.ConsentLocationF
JOINtbBuildingBONB.BuildingNumber=F.LocationCOLLATELatin1_General_CI_AS
JOINtbFloorFLONFL.BuildingID=B.BuildingID
WHEREF.Location=CL.LocationANDFL.FloorName=CL.[Floor]COLLATELatin1_General_CI_AS)
WHENCL.LocationISNOTNULLANDCL.[Floor]ISNOTNULLANDCL.RoomISNOTNULLTHEN
(SELECTTop1
R.RoomIDFROMPMIS.dbo.ConsentLocationF
JOINtbBuildingBONB.BuildingNumber=F.LocationCOLLATELatin1_General_CI_AS
JOINtbFloorFLONFL.BuildingID=B.BuildingID
JOINtbRoomRONR.FloorID=FL.FloorID
WHEREF.Location=CL.LocationANDFL.FloorName=CL.[Floor]COLLATELatin1_General_CI_ASANDR.RoomNumber=CL.RoomCOLLATELatin1_General_CI_AS)
ENDasParentID
I have written this case when statement above to find a ParentID. I have got the case when statement to work individually, e.g. I get the correct records back. However when I put it into a insert statement, as I want this ParentID to go
into a column in a table I get an error with the following message.
Cannot insert the value NULL into column 'ParentID', table 'K2_Master_4_Test.dbo.tbConsentLink'; column does not allow nulls. INSERT fails.
Can someone point me in the right direction, as to what I need to do to get this case when statement working? Also no I cannot change the structure of the table to allow for null values either. So I need to modifiy this one.The error is valid because your table column has 'not null' constraint and when your case expression does not satisfy either of the 'when' conditions, it is returning NULL to the insert statement.
you can get around this by defining a generic value. Simple Example
select case when <<Column>>=1 then 'First' When <<Column>>=2 then 'Second' Else 'Last' End
In this case, when column value is not 1 or 2, it will insert 'Last'.
So, you have to do something like this...i.e add ELSE condition to your case..
Hope it Helps!! -
SUM(CASE WHEN statement is not returning proper result.
Hi Folks,
I'm an end-user on OBIEE 11g creating a custom analysis. I'm trying to SUM a particular case statement: SUM(CASE WHEN "MyMeasureColumn.Here" LIKE '%~25~%' OR "MyMeasureColumn.Here" LIKE '%~26~%' OR "MyMeasureColumn.Here" LIKE '%~27~%' OR "MyMeasureColumn.Here" LIKE '%~28~%' THEN 1 ELSE 0 END)
The result should be about 6,700 however I am getting only 1,900. Any ideas?>
Ive done a manual validation of the statement (in excel) and know its near 6700. I think it has something to do with the type of data it is?
>
Well there are only three possibilities that I can think of.
1. The data in Excel is different than the data in Oracle
2. The 'manual validation' is different than what the query that you are using does
3. Both #1 and #2
You are the only one with access to the data.
You are the only one that has any idea what your 'manual validation' was.
If necessary you will need to use the brute force 'divide and conquer' method.
Use a small amount of data and compare your 'manual validation to your query results. If they are not the same figure out why.
If they are the same then repeat the process with another set of the data. -
Hi, another case statement question. My set up is calling from dasnboard prompt to publisher with an rtf template. My question is whether my logic/syntax is corrected. Thank you.
and "office"."branch" = ( CASE WHEN :BRANCH = '' THEN "office"."branch" ELSE :BRANCH END)
case when :BRANCH is null THEN 'or' ELSE 'and' END -----> (here I want to be able either or / and in case when edit box with BRANCH parameter is null use OR operator and when BRANCH parameter is field use AND operator.
and "office"."employee" like upper( CASE WHEN :EMPLOYEE = '' THEN "office"."employee" ELSE :EMPLOYEE END)try this in TOAD (replace each apostrophe of your sql by two apostrophes and add the starting and ending apostrophe to obtain a string)
execute immediate 'INSERT INTO DATAMART.PERSONSITE (PERSON_DBID,SITE) SELECT PDBIDSKILL.DBID, MIN(PDBIDSKILL.SKILL) FROM
(SELECT DISTINCT DATAMART.V_CFG_PERSON.DBID, CASE WHEN DATAMART.V_CFG_SKILL.NAME=''Complex_Rslve'' OR DATAMART.V_CFG_SKILL.NAME=''Broadband_Business_Resolve'' THEN ''BBHD'' WHEN DATAMART.V_CFG_SKILL.NAME=''General'' OR DATAMART.V_CFG_SKILL.NAME=''General_Mobile'' OR DATAMART.V_CFG_SKILL.NAME=''General_Billing'' THEN ''MASS'' WHEN DATAMART.V_CFG_SKILL.NAME=''Faults_General'' OR DATAMART.V_CFG_SKILL.NAME=''Faults_Business'' THEN ''Faults'' ELSE ''_Other'' END AS SKILL
FROM DATAMART.V_CFG_SKILL INNER JOIN DATAMART.V_CFG_SKILL_LEVEL ON DATAMART.V_CFG_SKILL.DBID = DATAMART.V_CFG_SKILL_LEVEL.SKILL_DBID
INNER JOIN DATAMART.V_CFG_PERSON ON DATAMART.V_CFG_PERSON.DBID = DATAMART.V_CFG_SKILL_LEVEL.PERSON_DBID) PDBIDSKILL GROUP BY PDBIDSKILL.DBID';it should give the same result as your original sql statement
before using the string in VBA you must replace '' with the characters used to denote an apostrophe within apostrophes.
I don't know nothing about VBA but I'm sure you'll know how to deal with it (an apostrophe within apostrophes).
Regards
Etbin -
Hi,
I hav an urgent requirement to implement as below:
Have a column 'Category' which is getting computed based on measure. Category column is getting computed in logical fact itself based on the values of measure.
e.g Case when sum(measure value)<250$ then 'less dollars'
when sum(measure value)>250$ then 'more dollars' end
Issue : While pulling the both columns in answer it is just showing the total sum of measures along with the category as 'more dollars' which is not the case.
root cause: In sql,its not doing group by category. What is the solution to solve this?
Please reply ASAP.
Regards,
RajeevLooks like you don't need a group by here, please let me know the fields you have in the report with a sample data.
Unless you have a dimension, it will not do a group by.
Maybe you are looking for
-
Results using Parameters with Preview Sample
I'm trying to test the Parameters I created for my report using the Preview Sample. I select criteria using clients and dates that I know exist, but when I click ok, the results show all of the data and not the data that meets the criteria. We use a
-
I read all other posts about this problem from December 2012 and apparently the iTunes update fixed the problem. Not for me. I find myself having to use an older computer with a very old version of iTunes to print a CD insert. This seems like a ve
-
I just wanted to say thanks to all the NI folks, Lego folks, and Mindstorms fans at NIWeek. It was great to meet many of the community members and some of the behind-the-scenes folks. I hope I get to meet more of the community and renew this yea
-
Am I able to imessage from my iphone in the US to an ipod user in Germany?
Am I able to imessage from my iphone in the US to an ipod user in Germany?
-
How to activate my Adobe Acrobat 8 Professional
Unable to activate my Adobe Acrobat 8 Professional