ora-00939 error in reporting services, SSRS - sql

I have an SSRS report, Oracle is my backend and am using this following query for dataset of my second parameter.
select distinct X
from v_stf_sec_user_staffing_center usc
where usc.center_group_id in (
select distinct center_group_id from V_T_STAFFING_CENTER_GROUP scg
where INSTR(','||REPLACE(:PI_REGION_LIST,' ')||',', ','||scg.group_abbreviation||',') > 0)
and usc.nt_user_name=:PI_NT_USER_NAME
Here PI_REGION_LIST is a multivalued parameter of string type.
and PI_NT_USER_NAME is a default string valued parameter
This query works fine when I try to execute in manually in the Data tab, also in the Oracle tool. But when I run the report in SSRS and select more than 3 values for the parameter PI_REGION_LIST the report throws an error on this dataset
ora-00939 error,too many arguments for function.
I am not able to figure out the error here.
Please help me with an idea.

The REPLACE function takes three string parameters, the last being optional.
The MS documentation says a multi-valued parameter has the following restriction
"The query must use an IN clause to specify the parameter."
If you don't actually need to do the REPLACE to get rid of spaces, you should be able to do something like
WHERE scg.group_abbreviation in (:PI_REGION_LIST)

Related

pass string in SSRS parameter, without double quotes

I am trying to allow the user to pass a text parameter in an SSRS report like this:
'value1','value2','value3','value4'
The idea is to use it in my dataset query in a where in clause.
I think SSRS passes the above parameter to the query like this:
"'value1','value2','value3','value4'" which messes up my query.
How can this work?
Yes you can definitely do that,
You need to create parameter as below
Then If you are using sql statement you can use in your sql statement as
select * from customer where customerid=#ReportParameter1
Here are 2 links for Ref
https://reportsyouneed.com/ssrs-tip-put-parameters-in-your-query-not-your-filter/
https://learn.microsoft.com/en-us/sql/reporting-services/tutorial-add-a-parameter-to-your-report-report-builder?view=sql-server-2017#Query

Passing multiple parameter values to crystal reports using SQL

I have in my report a few needed arguments like 'A','B','C' and I would like to pass it using SQL.
How can I do that?
I tried prm_szDiscType='C','N','P' , prm_szDiscType = C,N,P, and prm_szDiscType=''C'',''N'',''P''
I'm not sure how you pass parameters via URL.
In Crystal Reports desktop client, I created a Command Parameter with "Allow multiple values" check on.
Then in my Command SQL, I use a where clause such as:
where item in {?Item}
When you check "Allows multiple values" on, Crystal will create the clause after in. If you select Value Type of String, the values you enter will automatically be wrapped in single quotes.
Credit to ExpertsExchange thread on command parameters ;)

Passing a Parameter in Oracle Using SSRS Report

This is my Query In SSRS Report:
SELECT
GTCODE,
COUNT(GTCODE),
SUM(HLD_FLG),
Reason
FROM ICWGHC.W_STOCKINFO
WHERE GTCODE IN (?GTC)
GROUP BY GTCODE, Reason;
I have Connected SSRS to ORACLE through ODBC.
I have to pass the parameter GTC, I have created another Dataset for the parameter.
And when i execute the query i get this message
ERROR ORA 00907 missing right parenthesis
Please help me.
For ODBC data sources, no need to specify the parameter name after the question mark. You can use
SELECT
GTCODE,
COUNT(GTCODE),
SUM(HLD_FLG),
Reason
FROM ICWGHC.W_STOCKINFO
WHERE GTCODE IN (?)
GROUP BY GTCODE, Reason;
After editing the query go to the parameters tab to correctly map the parameter. Replace the Parameter value with (assuming your parameter name is GTC):
=Join(Parameters!GTC.Value,",")

how to use common function in query expression?

I want to use the "split" function in a simple query on my SSRS 2008 report. However, I get an error "Query execution failed for dataset "SlsmRealNum". "Split" is not a recognized built-in function name". But it's listed as a common function (text) if I open up the Expression box on the query, so not sure why it's failing?
my simple select statement is:
select slsm_num, slsm_msid from Salesman where slsm_msid = split(User.UserID,"\").GetValue(1)
right now to get the report to work, I have one parameter (SlsmnNum) that has the Split expression in it (to get the MSID of the user) and then a 2nd parameter that uses the above query in the Dataset Salesrepum using the #SlsmnNum parameter as the MSID. I'd like to not have to have 2 parapmeters if possible and just get the actualy salesrep # in just one. Any help is greatly appreciated!
Your select statement is executed as SQL so the error you are getting is actually from SQL server. This may be where you are getting confused.
There are two components to SSRS - SQL Statements and Report Expressions. Typically, SQL statements are used to generate datasets by querying the database. Report expressions are used to organize, aggregate, and filter the dataset once obtained from the SQL database. Since the SQL statement is executed IN the SQL database, only the functions that are in the database are available. The code you posted is a SQL statement not a Report Expression.
For example, you can't take a Report Expression and expect it to work in SSMS? No, because they are two different entities with wholly different syntax and purpose. When it comes to using built-in SSRS functions inside a SQL statement it will not work, the database has no concept of what the built in User.UserId is and as such you must use a parameter to transport the value over to the SQL query. This is definition and purpose of a parameter and why they exist.
Split is a function in SSRS which is why you see it in your expression reference, however, it is not a function in SQL. The code you posted is SQL syntax, so I am betting that this is the SQL statement that you are using to obtain your dataset. Therefore the query fails since the SQL DB does not have a Split Function.
You can add this split function to your database and the code is located here: Split String in SQL. You could also use something along the following in your where clause, the following is your updated SQL statement.
SELECT slsm_num, slsm_msid from Salesman where slsm_msid = SUBSTRING(#UserId, PATINDEX('%\%', #UserId), LEN(#UserId))
You would set the #UserId parameter's value to an expression of User!UserID rather than specifying it in your select statement.
The SSRS expression examples have a function similar to what your code is trying to accomplish if you were wanting the same thing in the report side. The function you are looking for is InStr(). On your report side you could use something along the lines of:
=Parameters!User.Value.Substring(Parameters!User.Value.IndexOf("\")+1, Parameters!User.Value.Length-Parameters!User.Value.IndexOf("\")-1)
Expression examples can be found here: MSDN Expression examples.

How to call SQL Command with custom parameters in field (Crystal Reports)?

I have a custom SQL expression with some parameters.
I've added it to Field Explorer correctly.
But I couldn't find an example of syntax for using pre-defined parametrized SQL command with my own non-default parameters.
For example, there is a SQL expression like this (it's body of SQL command):
select count(*) from table A where A.col1 > {?param}
I want to create a set of fields with different parameters.
What should I to do?
Is it possible?
Version of CR is 11, SQL syntax is Oracle SQL.
Thank in advance.
You can't use parameter field in a SQL-expression field.
You can, however, use a parameter field with a Command object (assuming that the parameter was defined in the Command object)