Passing a Parameter in Oracle Using SSRS Report - sql-server-2012

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,",")

Related

How to pass sql parameter in DAX query in SSIS

Does anyone know how to pass a parameter to DAX query in SSIS?
I know that when using OLEDB Source in SSIS we can use "?" to pass a parameter to the query. To further clarify, the query should look like this 'select region from table where region = ?';
Similarly, how to pass a parameter to a DAX Query within SSIS? I have tried with "#" but it didn't work.
Well, I found the answer at last.
I captured the output of SQL query in a variable using "single Result Set" in Execute SQL task.For example var1 = "tableA"
Then I created another variable for example -DAX_Var which holds the dax query in the form of expression like this "Evaluate Summarize" + #user::var1
Bring a DFT, bring an OLE DB source. Use SQL command from variable and instead of pointing table, I point the variable name. Ie DAX_Var
In this way, I was able to connect my SQL variable and bring it inside the DAX query.
It worked Flawlessly

how to add a parameter to a part "from" into sql query in pentaho?

I use postgreSQL/pentaho CDE. I need to transmit parameter as schema prefix in my query. I need to run this query: select * from peredelkino_public.protocol
I used custom parameter in Pentaho (named 'selector_par'), in properties named 'Javascript code' i wrote 'peredelkino_public.protocol'.
Then I changed sql query in component 'sql over sqlJndi' like this: select * FROM (${selector_par})
But this query doesn't work! I get message 'Error processing component'. How I can transmit schema prefix in my query?
Check the Replace variables in script.
Note: if the parameter selector_par does not exists or is misspelled, you may get a hard to understand error message.
You cannot.
CDE can only use JDBC parameters and those cannot be used in the from clause.
If you absolutely need to do that, you should use a Kettle datasource in CDE, as PDI allows any variable to be used in any part of a SQL query.
But make sure you sanitize your inputs. Variable replacements such as that one are a gold mine for hackers.

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)

ora-00939 error in reporting services, SSRS

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)