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

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)

Related

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.

Declare SQL construct or statement is not supported for simple query

I have simple SQL Query and need to get the input from parameter. I am getting the when i click parameter button. Please let me know how to get the parameter if i have declare statement in my scripts.
Note :OLEDB connection manager used for connection
You can't use parameters in an OLEDB Source if your command contains DECLARE, or anything other than a single SELECT statement.
The way to do what you want is to use build your entire SQL Command into a single SSIS variable, and use the "SQL Command from variable" option in the OLEDB source.
EDIT based on comments:
If you have to handle a SQL Command over 4000 characters, the only way to do it is in a Script Component. The SQL Command in a script component can be any length. Here is an example.

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 do I pass system variable value to the SQL statement in Execute SQL task?

SSIS 2008. Very simple task. I want to retrieve a System Variable and use it in an SQL INSERT. I want to retrieve the value of System:MachineName and use it in an insert statement.
Using the statement INSERT INTO MYLOG (COL1) SELECT #[System::MachineName] gives the error Error: ..failed to parse. Must declare the scalar variable "#"
Using the statements SELECT #System::MachineName or SELECT ##[System::MachineName] gives the error 'Error Incorrect systax near '::'
I am not trying to pass a parameter to the query. I have searched for a day already but couldn't find how to do this one simple thing!
Here is one way you can do this. The following sample package was created using SSIS 2008 R2 and uses SQL Server 2008 R2 as backend.
Create a sample table in your SQLServer database named dbo.PackageData
Create an SSIS package.
On the SSIS, add an OLE DB connection manager named SQLServer to connect to your database, say to an SQL Server database.
On the Control flow tab, drag and drop an Execute SQL Task
Double-click on the Execute SQL task to bring the Execute SQL Task Editor.
On the General tab of the editor, set the Connection property to your connection manager named SQLServer.
In the property SQLStatement, enter the insert statement INSERT INTO dbo.PackageData (PackageName) VALUES (?)
On the Parameter Mapping tab, click Add button, select the Package variable that you would like to use. Change the data type accordingly. This example is going to insert the PackageName into a table, so the Data Type would be VARCHAR. Set the Parameter Name to 0, which indicates the index value of the parameter. Click OK button.
Execute the package.
You will notice a new record inserted into the table. I retained the package name as Package. That's why the table
Hope that helps.
Per my comment against #ZERO's answer (repeated here as an answer so it isn't overlooked by SSIS newcomers).
The OP's question is pretty much the use case for SSIS property expressions.
To pass SSIS variables into the query string one would concatenate it into an expression set for the SqlStatementSource property:
"INSERT INTO MYLOG (COL1) SELECT " + #[System::MachineName]
This is not to suggest the accepted answer isn't a good pattern, as in general, the parameterised approach is safer (against SQL injection) and faster (on re-use) than direct query string manipulation. But for a system variable (as opposed to a user-entered string) this solution should be safe from SQL injection, and this will be roughly as fast or faster than a parameterised query if re-used (as the machine name isn't changing).
I never use it before but maybe you can check out the use of expression in Execute SQL task for that.
Or just put the whole query into an expression of a variable with evaluateAsExpression set to true. Then use OLE DB to do you insert
Along with #user756519's answer, Depending on your connection string, your variable names and SQLStatementSource Changes

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)