The default expression for the query parameter contains an error - ssrs-2008

I have a dataset referencing a proc. That proc takes in a #UserName
In my parameters of my dataset, I have specified a new param called #UserName and for its default value the expression =User!UserID but I still get this error when the report tires to render:
The default value expression for the query parameter #UserName contains an error [BC30654] 'Return' statement in a function, Get, or Operator must return a value
The only thing I can think of is that instead of modifying the existing datasource I had defined in the report, I removed and added a new datasource. I hope that doesn't matter as long as there is a valid data source for the report to go on that has those fields...I just switched this report to reference a copy of our current database for testing purposes.

Sounds like the report parameter is not being passed to the stored procedure.
In the Dataset Properties, click on the Parameters tab and check that the stored proc parameter #Username is correctly mapped to the Report parameter #Username.

Related

Spliting data in a db2 table using function

I'm trying to select data using below sql and created the following function to split the data but I get SQL0440n error.
The error "SQL0440n" simply means that a function (aka routine) in your SQL statement has not been found.
SQL0440N No authorized routine named "<routine-name>" of type
"<routine-type>" having compatible arguments was found.
If it is a user defined function, you will need to qualify it with a schema name when you use it, or alter your CURRENT PATH to let Db2 find the function by looking in a given set of schemas.
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001014.html
If you still get the same error, check that the data-types of the input values to the function match, or are implicitly castable to the data-types in your function parameters

Unable to dynamically change value for static label column header

I am unable to dynamically change the column header values during run time while creating a jasper report. Why do I keep getting string to boolean cast exception everytime I assign the value to table element's column header??
I have a column header that is a part of the table element. And this table and its dataset are not a part of the main data set. I want to the column header to change dynamically based on values in the main dataset. The main dataset and sub data set return different resultsets
The steps I followed were:
create a variable called v1_enabed (string) and v1_display(string) in the main dataset. I also assigned the required fields(from the main data set) to these variables
I created a parameter p1(string) in subdataset
I use the subdataset fields for table creation. I used the table element.
I go the table and map the parameter p1(string) to the table. And I assign the expression ($V{v1_enabled} == Character.toString('1')) ? $V{v1_display} : $V{v1_display} to it
Until here whenever I run the report, I do not get any error.
Now, I go the table. Pick up the 5th column and assign this in the print when expression section -- $P(p1)
Now, comes the error: java.lang.String cannot be cast to java.lang.Boolean
How do I solve this?

PHP and sanitizing strings for use in dynamicly created DB2 queries

I'm relatively new to DB2 for IBMi and am wondering the methods of how to properly cleanse data for a dynamically generated query in PHP.
For example if writing a PHP class which handles all database interactions one would have to pass table names and such, some of which cannot be passed in using db2_bind_param(). Does db2_prepare() cleanse the structured query on its own? Or is it possible a malformed query can be "executed" within a db2_prepare() call? I know there is db2_execute() but the db is doing something in db2_prepare() and I'm not sure what (just syntax validation?).
I know if the passed values are in no way effected by the result of user input there shouldn't be much of an issue, but if one wanted to cleanse data before using it in a query (without using db2_prepare()/db2_execute()) what is the checklist for db2? The only thing I can find is to escape single quotes by prefixing them with another single quote. Is that really all there is to watch out for?
There is no magic "cleansing" happening when you call db2_prepare() -- it will simply attempt to compile the string you pass as a single SQL statement. If it is not a valid DB2 SQL statement, the error will be returned. Same with db2_exec(), only it will do in one call what db2_prepare() and db2_execute() do separately.
EDIT (to address further questions from the OP).
Execution of every SQL statement has three stages:
Compilation (or preparation), when the statement is parsed, syntactically and semantically analyzed, the user's privileges are determined, and the statement execution plan is created.
Parameter binding -- an optional step that is only necessary when the statement contains parameter markers. At this stage each parameter data type is verified to match what the statement text expects based on the preparation.
Execution proper, when the query plan generated at step 1 is performed by the database engine, optionally using the parameter (variable) values provided at step 2. The statement results, if any, are then returned to the client.
db2_prepare(), db2_bind_param(), and db2_execute() correspond to steps 1, 2 and 3 respectively. db2_exec() combines steps 1 and 3, skipping step 2 and assuming the absence of parameter markers.
Now, speaking about parameter safety, the binding step ensures that the supplied parameter values correspond to the expected data type constraints. For example, in the query containing something like ...WHERE MyIntCol = ?, if I attempt to bind a character value to that parameter it will generate an error.
If instead I were to use db2_exec() and compose a statement like so:
$stmt = "SELECT * FROM MyTab WHERE MyIntCol=" . $parm
I could easily pass something like "0 or 1=1" as the value of $parm, which would produce a perfectly valid SQL statement that only then will be successfully parsed, prepared and executed by db2_exec().

Accessing Parameters from the Main Data Source from A Secondary Dataset

I've got a chart that uses a secondary dataset. It allows for the use of the fields and parameters of the second dataset, however I'm not able to use the parameters set in the main report dataset. Does anyone have any clue how to access the values of the parameters?
For example
I have the following parameters in the main dataset:
valueOne
valueTwo
And a secondary data set:
fieldOne, fieldTwo
From the chart that is set to use the second dataset, how would I request parameter: "valueOne"?
Add a parameter to your subDataset that has the exact same name as the parameter in the main dataset. Leave the default value expression blank and do not prompt for a value. When you reference the parameter in the subdataset, the value from the main dataset will be returned.
So in your case monksy, you should add an empty parameter named "valueOne" to your second dataset.
I've never seen this behaviour documented anywhere; I found it out by accident when working on a report.

how to pass null value when the parameters are left in empty

I am developing a Crystal Report from the database, and am setting a parameter's value in Crystal Reports itself, with a Command object. My issue is that when I run the Crystal Report, if I leave any parameter as null, it will return all the records from the database. How is that possible?
If you're using parameters in a Database Command, you can't use optional parameters. However, if you're using CR2008 (I think that's when they were added), you can set your parameters as optional, and then use the HasValue() function to see if the user selected a value.
RecordSelection:
If HasValue({?MyParm}) Then
{Command.MYFIELD} = {?MyParm}
Else
True;
Crystal Reports requires each Parameter Field to have a value; nulls aren't allowed.
If you are using a Command object, you will need to use syntax like this in SQL:
--t-sql syntax; assumes numeric value and -1 is the value chosen to represent 'all values'
WHERE table.field = CASE
WHEN {?command_object_prompt} = -1 THEN table.field
ELSE {?command_object_prompt}
END
If you are using 'standard' database linking (as opposed to a Command object), look at my posting Crystal Reports: Optional-Multi-Select Parameters.