Error in CASE statement used in Reports query
My query has lots of selection criteria. I'm trying to use CASE for that.
This is a part of my query with parameters:
AND ad.location IN (CASE &p_location
WHEN 1 THEN
(SELECT TRIM(code_nbr) FROM code_detail
WHERE code_nbr like 'LC%')
WHEN 2 THEN -- then the user can type in more than 1 locations
&p_location1|| p_location2
END)
AND --- there are more conditions after this
The query fails that invalid relational operator in this CASE statement.
Any suggestions...is there any other way to do it...Thanks in advance
I would recommend the use of lexical parameters in the before report trigger
Set up a parameter SQL_WHERE - text, 4000 chars.
In your datamodel get rid of the case statement and just put &SQL_WHERE
In the before report trigger modify your case statement to be something like:
&SQL_WHERE:=' and ad.location in ';
case when :p_location = 1 then
&SQL_WHERE:=&SQL_WHERE||' select trim(code_nbr) from code_detail etc';
end
This way you can debug and test your case statement in the pl/sql environment. Plus the query should run faster as you are moving the complex where statement into a separate part of the report
Similar Messages
-
'Missing select' error for update statement using WITH clause
Hi,
I am getting the below error for update statement using WITH clause
SQL Error: ORA-00928: missing SELECT keyword
UPDATE A
set A.col1 = 'val1'
where
A.col2 IN (
WITH D AS
SELECT col2 FROM
(SELECT col2, MIN(datecol) col3 FROM DS
WHERE <conditions>
GROUP BY PATIENT) D2
WHERE
<conditions on A.col4 and D2.col3>Hi,
The format of a query using WITH is:
WITH d AS
SELECT ... -- sub_query
SELECT ... -- main query
You don't have a main query. The keyword FROM has to come immediately after the right ')' that ends the last WITH clause sub-query.
That explains the problem based on what you posted. I can't tell if the real problem is in the conditions that you didn't post.
I hope this answers your question.
If not, post a complete test script that people can run to re-create the problem and test their ideas. Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Case statement in a multiple query
Hi everyone,
This is my first time to use case statement in a multiple query. I have tried to implement it but i got no luck.. Please see below
set define off
SELECT g.GROUP_NAME as Market
,t.NAME as "Template Name"
,t.TEMPLATE_ID as "Template ID"
,(SELECT created
FROM material
where template_id = t.template_id) as "Date Created"
*,(SELECT DESTINATION_FOLDER_ID,*
CASE DESTINATION_FOLDER_ID
WHEN NULL THEN 'Upload'
ELSE 'HQ'
END
from log_material_copy
where destination_material_id in (select material_id
from material
where template_id = t.template_id ))as "Origin"
,(select material_id
from log_material_copy
where destination_material_id in (select material_id
from material
where template_id = t.template_id)) as "HQ/Upload ID"
,(SELECT COUNT (mse.ID)
FROM MATERIAL_SEND_EVENT mse, material m, creative c
WHERE mse.MATERIAL_ID = m.MATERIAL_ID
AND mse.MATERIAL_TYPE_ID = m.MATERIAL_TYPE_ID
AND m.ASSET_ID = c.id
AND c.TEMPLATE_ID = t.TEMPLATE_ID) as Sent
,(SELECT COUNT (de.ID)
FROM download_event de, material m, creative c
WHERE de.MATERIAL_ID = m.MATERIAL_ID
AND de.MATERIAL_TYPE_ID = m.MATERIAL_TYPE_ID
AND m.ASSET_ID = c.id
AND c.TEMPLATE_ID = t.TEMPLATE_ID) as Download
,(SELECT 'https://main.test.com/bm/servlet/' || 'UArchiveServlet?action=materialInfo&materialId=' || DESTINATION_MATERIAL_ID || '&materialFolderId=' || DESTINATION_FOLDER_ID
from log_material_copy
where destination_material_id in (select material_id
from material
where template_id = t.template_id)) as "URL to template on MPC layer"
--, t.AVAILABLE_FOR_TRANSFER as "Available for transfer"
FROM template t, layout l, groups g
WHERE t.LAYOUT_ID = l.LAYOUT_ID
AND l.ORGANIZATION_ID = g.IP_GROUPID
AND g.IP_GROUPID in ( 1089, 903, 323, 30, 96, 80, 544, 1169, 584, 785, 827, 31, 10, 503, 1025 )
ORDER BY g.GROUP_NAME ASC;
The one in bold is my case statement.. Please let me know what is wrong with this.
Regards,
JasI think you're getting the idea, but:
You're still selecting 2 columns in the (scalar) subquery. Did you read the link I posted for you?
"a) scalar subqueries - *a single row, single column query that you use in place of a "column"*, it looks like a column or function."
You must move that query outside, join to template.
Something like:
NOT TESTED FOR OBVIOUS REASONS SO YOU'LL PROBABLY NEED TO TWEAK IT A BIT
select g.group_name as market,
t.name as "Template Name",
t.template_id as "Template ID",
m.created as "Date Created",
lmc.destination_folder_id,
case lmc.destination_folder_id
when null then 'Upload'
else 'HQ'
end as "Origin"
(select material_id
from log_material_copy
where destination_material_id in
(select material_id
from material
where template_id = t.template_id)) as "HQ/Upload ID"
(select count(mse.id)
from material_send_event mse, material m, creative c
where mse.material_id = m.material_id
and mse.material_type_id = m.material_type_id
and m.asset_id = c.id
and c.template_id = t.template_id) as sent
(select count(de.id)
from download_event de, material m, creative c
where de.material_id = m.material_id
and de.material_type_id = m.material_type_id
and m.asset_id = c.id
and c.template_id = t.template_id) as download
(select 'https://main.test.com/bm/servlet/' ||
'UArchiveServlet?action=materialInfo&materialId=' ||
destination_material_id || '&materialFolderId=' ||
destination_folder_id
from log_material_copy
where destination_material_id in
(select material_id
from material
where template_id = t.template_id)) as "URL to template on MPC layer"
--, t.AVAILABLE_FOR_TRANSFER as "Available for transfer"
from template t
, layout l
, groups group by
, MATERIAL M
, LOG_MATERIAL_COPY LMC
where t.layout_id = l.layout_id
and l.organization_id = g.ip_groupid
and M.TEMPLATE_ID = t.template_id
and LMC.destination_material_id in ( select material_id
from material
where template_id = t.template_id
and g.ip_groupid in (1089,
903,
323,
30,
96,
80,
544,
1169,
584,
785,
827,
31,
10,
503,
1025)
order by g.group_name asc; -
How to Generate a MDX statement using a BEX query
Hello,
Is there any possiblity in BW to generate a MDX statement using a BEx query?
Thanks,
RaviBW does not generate any MDX statement for Bex query.I have tried ample number of times to acheive this but failed.
Like an Infocube the Query is also an object where in you can write MDX queries on BEx Queries.
As it is I never found BW rendering MDX queries.But with MDX queries you can get something but how far it helps I don't know.
RSCRM_BAPI is obsolete and it is recommended to use RSCRM_REPORT somewhere I have read ,but when I went to that transaction I never found that "MDX" button at all.
It was converted to "OLAP Check" which gave me some warning on the key figures and that's it.
Somehow I feel BW is not comfortable with MDX.
Regs
Gopi -
Using crystal reports query (.qry) as datasource in crystal 9
I have a problem using crystal reports query as a datasource in crystal reports 9. When Im using a report withing application i cannot change database or server property of the query.
For example - during report design im using one odbc for query but I want to change it during runtime.
Changing any options beside username or password results in external exception. Im using Builder XE as application environment.
I tried switching to SQL commands which works but i lose all the fields on report when changing from query to report.
Is there a way to make query work or to change query to sql command without losing all the fields (and putting them back on the report manually)?Hello,
Unfortunately .QRY files are no longer supported as of CR 9. We replaced it with the Command Object where it basically did the same thing only you had to write the query yourself.
The problem is because the Command Object can be anything CR has no way of mapping a query to the database field within the report so it auto deletes all of the fields.
The only way is to create new reports, you can open the original report in one window and then create your new report, copy the SQL into the Command windows and then copy and paste the report objects from the window with the old report into the new report window.
There is no migration wizard to do this. I have heard of others who used the RAS server or RDC to get the objects from one report and .add them to the new report. Depending on the number of reports you have depends on if it is worth the time writing that app or just rebuild all of your reports.
Thank you
Don -
SQL Query CASE statement using two fields
Hi,
I have two fields. One is called rescategory1, the other is called rescategory2.
I'm not sure if its a CASE statement I need or some sort of WHERE clause but I want to create a query that does the following or something similar:
CASE rescategory2
WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
END AS [Resolution Sub Category]
Basically, I'm looking to give rescategory2 a value based on that of rescategory1 and rescategory2 combined.
How do I write this?
Cheers
Pauldo you mean this?
rescategory2 = CASE
WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
END
ie assigning value for rescategory2
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Case statement for interactive report error
The case computation does not work for me :
statement
CASE WHEN G = 7 THEN G ELSE C END
Error message ' Invalid computation expression. THEN'
It does not seem to matter what the case statement is IE :
CASE WHEN I = 'DEMO' THEN 'LOW' ELSE 'HIGH' END
I have tried this on the Sample Application that is installed on my oracle workspace account
Column G : order number ( number)
Column C:order total (Number)
Column I:sales Rep ( String)
Can someone please tell me what I am doing wrong ?
ThanksYour statement works for me exactly as you typed it:
SQL> select * from t;
G C
1 101
2 102
3 103
4 104
5 105
6 106
7 107
7 rows selected.
SQL> select CASE WHEN G = 7 THEN G ELSE C END
2 from t;
CASEWHENG=7THENGELSECEND
101
102
103
104
105
106
7
7 rows selected. -
Error while trying to use '{' in the query
Hi,
The below mentioned query is giving Error while trying to use '{'
Query:
select s,x from table(SEM_MATCH(
'{?s rdf:type <http://www.cs.com/sbip/dwh/mdm/data_modeling#Base_Term> .
?s ?p ?x}',
SEM_Models('foundation'),
SEM_RuleBases('OWLPRIME'),
SEM_ALIASES(SEM_ALIAS('dm','http://www.cs.com/sbip/dwh/mdm/data_modeling#'),
SEM_ALIAS('owl','http://www.w3.org/2002/07/owl#')), null, 'INVALID'))
where regexp_like(x,'Customers','i');
Error details:
ORA-29532: Java call terminated by uncaught Java exception: oracle.spatial.rdf.server.TokenMgrError: Lexical error at line 1, column 1. Encountered: "{" (123), after : ""
ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 178
ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 67
ORA-06512: at line 4
I am unable to use Option, Filter in query.
Any solution?
Please let me know do i need to apply any patch?
Note: I am using Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
Regards,
Kavitha.Hi,
For OPTIONAL support in 11.1.0.7.0, you need the following patch
Patch 7600122: CURLY BRACE SYNTAX,VIRTUAL MODELS, NETWORK INDEXES AND HINTO FRAMEWORK SUPPORT
Support for SPARQL FILTERs in SEM_MATCH is not available for 11.1.0.7.0. You will need version 11.2.0.1.0 or later for FILTER support. With 11.2.0.1.0, we recommend that you apply our latest patch set:
Patch 9819833: SEMANTIC TECHNOLOGIES 11G R2 FIX BUNDLE 2
All of the above patches are available through My Oracle Support.
Thanks,
Matt -
CASE statement used in Oracle 10g -ORA-00934 Error
I am getting ORA-00934 group function not allowed. What am I doing wrong here.
Please advice.
select count( case WHEN TRUNC(so_due_Date) = sysdate
AND ne_state = 'GA'
AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
end)INTO v_due_today,
count( case WHERE TRUNC(so_due_Date) = sysdate + 1
AND ne_state = 'GA'
AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
end)INTO v_due_tomorrow
FROM tbl_cif_current ;
Thanks,
jaya.are you using this in pl/sql block or at SQl
there two things.
you are missing
1 missing )<--- closing para for the count.
2. if rou are using pl/sql block then INTO clause goes after all the column,
SELECT COUNT( CASE WHEN TRUNC(so_due_Date) = SYSDATE AND ne_state = 'GA' AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
END)),
COUNT( CASE WHERE TRUNC(so_due_Date) = SYSDATE + 1 AND ne_state = 'GA' AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
END))
FROM tbl_cif_current ;
or in pl/sql
SELECT COUNT( CASE WHEN TRUNC(so_due_Date) = SYSDATE AND ne_state = 'GA' AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
END)),
COUNT( CASE WHERE TRUNC(so_due_Date) = SYSDATE + 1 AND ne_state = 'GA' AND ((so_type LIKE '%CHANGE%') OR (so_type LIKE '%NEW%')) THEN 1
END))
INTO v_due_tomorrow,v_due_today
FROM tbl_cif_current ;typo correction
Message was edited by:
devmiral -
Need to Pass Active Directory Attributes into OBIEE for use in Report Query
Hi,
We're using OBIEE 11.1.1.5 and have integrated it with AD security. Users successfully log into OBIEE and BIP (which is integrated with OBIEE) using their network/AD accounts.
Next step for us is to be able to pass some AD attributes that are on the user accounts into OBIEE and BIP so we can restrict data queries for the person logged in.
I've searched the web and so far have only come up with specific steps for setting this up in BIP. Since BIP is integrated with OBIEE, we have not set any of the MSAD/LDAP security up there - it is all in OBIEE. I have been unable to find the equivalent for adding the attribute names for data query bind variables.
With our current setup, we are unable to filter the report data automatically based on who has logged into the application (analytics and BIP). We have security setup within the catalog so only certain AD groups can access objects, but beyond that we need to be able to secure the data using AD attribute information. For example, all of our users should be able to access an Open Purchase Order report, but they should only be able to see their own purchase orders - not everyone in the company.
Anyway, we're looking to be able to pass AD attributes into OBIEE so that we can use this data in our Analytics and BIP queries.
How can we get this setup?
Thank you in advance!
SuzanneA fairly common problem, see:
http://www.williamrobertson.net/documents/comma-separated.html
http://www.oracle-base.com/articles/misc/DynamicInLists.php
http://tkyte.blogspot.com/2006/06/varying-in-lists.html -
Code Error with Case Statement
Hi everyone,
I'm new to PL/SQL and APEX and I'm trying to get this code to work. It is supposed to insert an sysdate if the named fields are changed and then update the fields.
This is the code:
BEGIN
SELECT ATS_CLS_NAME, ATS_CEL_NAME, ATS_END_DATE,
CASE
WHEN
ATS_CLS_NAME <> :P6_ATS_CLS_NAME
AND ATS_CLS_NAME <> :P6_ATS_CEL_NAME
AND ATS_END_DATE is Null
THEN
UPDATE ATS_ALLOCATION
SET
ATS_ALLOCATION_ID = :P6_ATS_ALLOCATION_ID,
ATS_START_DATE = :P6_ATS_START_DATE,
ATS_END_DATE = SYSDATE,
ATS_CLS_NAME = :P6_ATS_CLS_NAME,
ATS_CEL_NAME = :P6_ATS_CEL_NAME,
ATS_EMP_ID = :P6_EMP_EMP_ID
ELSE
UPDATE ATS_ALLOCATION
SET
ATS_ATS_ALLOCATION = :P6_ATS_ALLOCATION,
ATS_START_DATE = :P6_ATS_START_DATE,
ATS_END_DATE = :P6_ATS_END_DATE,
ATS_CLS_NAME = :P6_ATS_CLS_NAME,
ATS_CEL_NAME = :P6_ATS_CEL_NAME,
ATS_EMP_ID = :P6_EMP_EMP_ID
FROM ATS_ALLOCATION
END CASE;
END;
And I get this error:
1 error has occurred
ORA-06550: line 12, column 7: PL/SQL: ORA-00936: missing expression ORA-06550: line 5, column 1: PL/SQL: SQL Statement ignoredBEGIN
UPDATE ATS_ALLOCATION
SET
ATS_ATS_ALLOCATION = :P6_ATS_ALLOCATION,
ATS_START_DATE = :P6_ATS_START_DATE,
ATS_END_DATE = CASE
WHEN ATS_CLS_NAME <> :P6_ATS_CLS_NAME
AND ATS_CLS_NAME <> :P6_ATS_CEL_NAME
AND ATS_END_DATE is Null
THEN SYSDATE
ELSE :P6_ATS_END_DATE
END,
ATS_CLS_NAME = :P6_ATS_CLS_NAME,
ATS_CEL_NAME = :P6_ATS_CEL_NAME,
ATS_EMP_ID = :P6_EMP_EMP_ID
END;
1 error has occurred
ORA-06550: line 18, column 3: PL/SQL: ORA-00933: SQL command not properly ended ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored ORA-06550: line 21, column 21: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with -
Error running app wich uses Cristal Reports XI in client PCs
Hello,
have Crystal Reports XI for Developers. I have develop an application qich connects with CR to show reports. When I try to execute the app in a client computer (not my developing machine) and i have an error when i try to connect and show a report.
The error is number 512 and its description: Print Engine not opened
In the developing computer there is no error because i have installed the desktop application, but i would like not to have to install the Desktop Application of CR in each client computer where i would like to run my application.
Whit dll,s or something else i need to avoid this problem??
Thanks.Hello,
crpe32 as a report engine was deprecated as of CR 9. But I now assume you maybe using Delphi? Would be more informative if you gave all this info first so we don't have to ask or guess...
Search here if you are using delphi on "delphi" and you'll find more info and how to's.
If you are not using Delphi then your only option now is to either move to the RDC which also was deprecated in CR XI R2 or use our .NET assemblies and upgrade to Visual Studio 2008 or 2010.
Thank you
Don -
Error in sql statement using names having '&'
I am trying a query to update name to "WALK & TALK"..It gives me error as it considers Talk as input parameter..and expects its value ..when try to execute
Hi
Before inserting SET DEFINE OFF.
raja -
Help with error select case statement (ORA-00932: inconsistent datatypes)
Hi,
I'm struggling to get my sql query work on Oracle..
I have a table MyTable with 5 columns ( Column1, Column2, Column3, Column4, Column5 ) all are of type NVARCHAR2.
I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2.
For example
If a row contains the following values,
Column 2 = a.b
Column 3 = 123
Column 4 = xyz
then column CA = a.b/123/xyz where column CA = temp column
If either Column 3 or Column 4 is empty/null, then I don't need to append value for that column..
For example
Column 2 = a.b
Column 3 = either NULL or ''
Column 4 = xyz
then CA = a.b/xyz where column CA = temp column
similarly..
Column 2 = a.b
Column 3 = 123
Column 4 = either NULL or ''
then CA = a.b/123 where column CA = temp column
Here is my query..
select MyTable.Column1 as CA0,
MyTable.Column2 as CA1,
MyTable.Column3 as CA2,
MyTable.Column4 as CA3,
MyTable.Column5 as CA4,
MyTable.Column2 + CASE WHEN MyTable.Column3 > '' THEN '/' + MyTable.Column3 ELSE '' END + CASE WHEN MyTable.Column4 > '' THEN '/' + MyTable.Column4 ELSE '' END CA
from MyTable;
This query works just fine against SQL Server db, but gainst Oracle I'm getting
ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
00932. 00000 - "inconsistent datatypes: expected %s got %s"
Could you please let me know what I'm doing wrong. I need to get this query working on both SQL Server and Oracle..
Please let me know your suggestions and thoughts..
Cheers,I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2. In Oracle, you can do it this way - no need to do all kinds of difficult things:
select col2||col3||col4
from tbl -
Using case statement in OWB expression builder
Hi All,
We are using OWB version 10.2.0.1.0. While using the below case statement We are getting the validation message as 'The expression is not properly formed'.
Case statement used in expression builder:
case when (INGRP1.CHARGETYPE in ('O','F') or INGRP1.TARIFF_GROUP in ('SMSINT','MMSINT')or ( INGRP1.CALL_TYPE = '002' and INGRP1.TARIFF_GROUP = 'MTV'))
then
(select call_zone_reltn_key from call_zone_reltn where
call_zone_cd=substr(case
when substr( INGRP1.B_SUBNO,1,2)='00'
then
substr( INGRP1.B_SUBNO,3)
else substr( INGRP1.B_SUBNO,1)
end,1,length(call_zone_cd))and rownum=1)
else -1
end
Kindly help me out in fixing this error or suggest any alternate way to use the above query in OWB expression builder.
Thanks,
Kabilan946887 wrote:
Hi All,
We are using OWB version 10.2.0.1.0. While using the below case statement We are getting the validation message as 'The expression is not properly formed'.
Did you try to deploy the mapping ? Some time the expression validator gives wrong error messege.
Try to deploy the mapping and see if you are still getting this issue
Case statement used in expression builder:
case when (INGRP1.CHARGETYPE in ('O','F') or INGRP1.TARIFF_GROUP in ('SMSINT','MMSINT')or ( INGRP1.CALL_TYPE = '002' and INGRP1.TARIFF_GROUP = 'MTV'))
then
(select call_zone_reltn_key from call_zone_reltn where
call_zone_cd=substr(case
when substr( INGRP1.B_SUBNO,1,2)='00'
then
substr( INGRP1.B_SUBNO,3)
else substr( INGRP1.B_SUBNO,1)
end,1,length(call_zone_cd))and rownum=1)
else -1
end
Kindly help me out in fixing this error or suggest any alternate way to use the above query in OWB expression builder.
Thanks,
Kabilan
Maybe you are looking for
-
Equium A80 - Black and white when plugging into PAL TV
I know this seems to be a common problem but I have searched this forum and it seems the soloution is to select PAL or a screen refresh rate of 50Hz. My Equium a80 has no option for PAL and the only screen refresh rate is 60Hz. Can anyone help?? Plea
-
Why does time machine not work?
First time machine was continually backing up, or not. Icon wouldn't respond. Started up on my Snow Leopard disk and it supposedly fixed the problem with disk utility. Now it will open time machine, but it doesn't work. I can't get a responce from th
-
SAP ECC 6.0 language problem
Hello! I have installed SAP ECC 6.0 UNICODE system, i had english and german languages as default, an i supplemented Romanian in client 000, before the client copy. I implemented all notes regarding the localization, but whenever i logon on the syste
-
I bought a song but did not get it! it said i downloaded but did not get it
i bought a song but it did not download on my account!
-
Will iPhoto 6 work with an older version of iMovie and iDVD?
Some time ago, I upgraded from iLife 4 to iLife 6 and iPhoto 6 works great, but when I try to use iMovie 6 or iDVD 6 they will not work, either because the processor speed is too slow or the OSX (10.3.9) is too old. Is it possible to use iPhoto 6 (I