OLE DB connection in SSRS doesn't like when parameters are repeated - oracle

I'm changing an Oracle based SSRS report and I'm having all sorts of issues with parameters.
The connection to Oracle is OLE DB.
My code is not doing anything complicated. I've only added in a new parameter. When I only have one instance of said parameter, it runs without any issues. As soon as I add it again, it bombs.
What I'm trying to do is show records if a parameter has a match. If no match, show all records.
I can run both queries in DBVisualizer without any issues.
This is what I've done
WHERE FieldName = nvl(:parameter, FieldName)
This one doesn't return the same results as this below
WHERE FieldName = :parameter
OR :parameter IS NULL
Problem is the second WHERE clause will not run in SSRS with an OLE DB connection. We cannot use another connection manager, unfortunately.
EDIT: Thanks to Hannover Fist, I was able to get this to work by doing this
I changed my WHERE clause to
WHERE FieldName = :parameter
OR :parameter2 IS NULL
Then mapped parameter2 to pull from the same SSRS parameter as the original parameter

I haven't found a good solution to this problem but I have worked around it by declaring the parameter in the Oracle SQL and mapping it to the SSRS parameter.
Then use the parameter created in the Oracle SQL in the rest of the query. This way you'll only use each SSRS parameter once.

Related

How to search for multiple values in a string column in a Cognos Oracle Query

I need to search an oracle table column for multiple word strings in cognos oracle query.
For example:
If Focus parameter returns multiple values as below
TRAINING
OMNIA
COUNTER
PROGRAM
And I need to search project.proj_name column like '%TRAINING%' or '%OMNIA%' or '%COUNTER%' or '%PROGRAM%'
I am trying below but I know it does only single value match not multiple. I want to know how to achieve multiple value match here.
'-99' in (#promptmany('Focus', 'string','-99')#) OR REGEXP_LIKE(proj_name, #promptmany('Focus', 'string','-99')#))
Working from Cognos Paul's solution to use output from promptmany as a table:
Assuming your query is named Q1...
Add a query. (Q2)
Add a SQL object to that query.
Set the Data source property for the SQL object.
Change the SQL Syntax property to IBM Cognos.
Define the query as
SELECT
parameterValue
FROM (VALUES
(#join('),(',split(',',promptmany('Scenarios','string',sq('N/A'))))#)
) query(parameterValue)
(change the names for your own use case)
Add a query. (Q3)
Add a join to the new query.
Add Q1 and Q2 to the empty boxes for the join leading to Q3.
Set the join as
[Q1].[proj_name] like '%' || [Q2].[parameterValue] || '%'
Add the required data items to Q3.
Since two keywords (from your parameter -> Q2) could be found in a single value (in Q1), you'll likely end up with duplicate rows. Cognos will probably handle this with its default aggregations, but keep a lookout.
Be careful with this. The new query (Q2) will probably be joined on the Cognos server, not on the database server. Be sure you have sufficient filters leading into this structure so Cognos is not trying to process your entire database.
This worked for me with SQL Server. I don't have an Oracle database to test against, but using IBM Cognos as the SQL Syntax should handle that.
To use REGEXP_LIKE to solve this problem, you'll need to get the second argument correct. I can't see any reason to see the error message ORA-00996: the concatenate operator is ||, not |, but I'm not working with your code in your system.
You don't specify which version of Cognos, or even which Cognos product, you are using. I'll assume Cognos Analytics 11.1.7.
To determine what Cognos Analytics is doing with your macro, create a very simple query with one item from the database (preferably from a very small table) and another data item that contains the macro. So the data item expression is:
#sq(join('|',split(',',promptmany('Focus','string','-99'))))#
When you run this, you may not be prompted. You'll see the value is -99. So to test this we'll need to remove the default so that the prompt becomes required.
#sq(join('|',split(',',promptmany('Focus','string'))))#
Be sure to enter more than one value when you test.
In my environment, the parameter returns a value that is my values surrounded by quotes (') and delimited by semicolons (;). So my tests produced the following:
expression
value
#sq(promptmany('Focus','string'))#
'PROGRAM';'COUNTER';'TRAINING'
#sq(join('|',split(',',promptmany('Focus','string'))))#
'PROGRAM';'COUNTER';'TRAINING'
#sq(join('|',split(';',promptmany('Focus','string'))))#
'PROGRAM'|'COUNTER'|'TRAINING'
replace(#sq(join('|',split(';',promptmany('Focus','string'))))#, '''', '')
PROGRAM|COUNTER|TRAINING
Your mileage may vary.
At this point, you know which macro to use in the REGEXP_LIKE function.

User-Defined Function Nested in Macro - Framework Manager

We are trying to create a dynamic query subject filter. To do this, we are trying to nest an Oracle user-defined function inside of a macro.
Example query subject filter:
#strip(ORACLE_USER_DEFINED_FUNCTION())#
We have imported the oracle function ORACLE_USER_DEFINED_FUNCTION into Framework Manager. The function returns a VARCHAR2 of the desired expression. For testing purposes, this function is simply returning VARCHAR2 value of '1=1' (the single quotes are not part of the VARCHAR2 return value).
The idea being that we want the query subject filter expression to be dynamically generated at run-time so the resulting query contains '...WHERE 1=1'. The strip macro is the mechanism to pre-process and invoke the user-defined function before the query is sent to the database.
However, when attempting to verify/check the query subject filter we receive the following error.
XQE-GEN-0018 Query Service internal error has occurred, please see the log for details.
I'm trying to get a hold of the query service log, but don't yet have it.
Perhaps there is some casting needed to convert the oracle VARCHAR2 output from the function to an IBM/Cognos string that is acceptable input for the IBM/Cognos macro.
Your assistance is appreciated. Thanks in advance.
Using Oracle 12c and Cognos 11.1.
With the exception of the queryValue macro function, macros are evaluated prior to accessing the database. This means the macro does not know what the Oracle UDF is or what its supposed to do. If you are able to call the UDF via a FM query subject you maybe able to get away with something similar to the queryValue answer found here:
Cognos 11.1.7 Framework manager change the table for the query subject, type data

Is it possible to display the result of complex query in SSRS 2012?

I'm new in SSRS and I want to know if it's possible to display a result of a complex query (which run perfectly on SSMS) in my report?
The problem is that I have an Over statement in my Query:
LEAD(Flow.MeasurementDate) OVER (Partition by
ComponentId, NominationCycle, LocationType, Frequency, FlowTypeId, UnitofMeasurement
ORDER BY MeasurementDate) nextMeasurement,
MAX(Flow.MeasurementDate) OVER (PARTITION BY
ComponentId, NominationCycle, LocationType, Frequency, FlowTypeId, UnitofMeasurement
) maxMeasurement
The error message is:
The OVER SQL construct or statement is not supported.
If it's possible please give me few steps to achieve this.
The Over construct is not supported by the SSRS query designer but the report should still work when the SQL is sent to Sql Server for processing.
If it doesn't, check that your database isn't running in a compatibility level where the Over construct is unsupported (80 or earlier).
If all else fails, an alternative is to put your query in a stored procedure and call that from SSRS.
That's just what SSRS is used for in general.
The steps are the same, no matter if it's a simple or complex query.
You use your query to fill a dataset and display this in a table on your report.
What you need is just a basic SSRS tutorial as it can be found here:
http://msdn.microsoft.com/en-us/library/ms167305.aspx

How to put a parameter into an query in SSRS 2008 R2 connected to an Oracle Database 11g

Putting a parameter into the query gets the following error:
"ORA-01036: illegal variable name/number"
The query is:
select * from t_accounts where account_number = #ReportParamter1
Without the where clause, the query runs fine
Any ideas?
thanx!
Abraham
Oracle wants its bound parameters to be denoted with colons, not # signs.
So you want
...where account_number = :ReportParamter1
O. Jones highlighted the root but didn't go into as much detail as I needed to address this same issue/question. I had created the parameter in Visual Studio and as noted it has the '#' in the format of the parameter so when applied to the Dataset I got the error message. Unfortunately in the construct of the parameter in VS (I'm using 12) there isn't anything in the various options that allows designating a : in place of the #. What I discovered was after manually adding the parameter to my query in the Dataset, I then found it listed in the parameters area of the Dataset Properties - the parameter entered in query was set to the parameter made in VS. I removed the original and preview processed without issue.

LINQ FormatException

I currently have an existing database and I am using the LINQtoSQL generator tool to create the classes for me. The tool is working fine for this database and there are no errors with that tool.
When I run a LINQ to SQL query against the data, there is a row that has some invalid data somehow within the table and it is throwing a System.FormatException when it runs across this row. Does anyone know what that stems from? Does anyone know how I can narrow down the effecting column without adding them one by one to the select clause?
Do you have a varchar(1) that stores an empty string?
You need to change the type from char to string in the designer (or somehow prohibit empties). The .net char type cannot hold an empty string.

Resources