How to use output of tMSSqlSP on a tJava element - sql-server

I have a tMSSqlSP element calling a procedure that receives two params and returns two values. If I connect a tLogRow right after that, I can see that the procedure is being called correctly and returning the correct values. However, I need to use those values in a tJava element, which means calling them explicitly somehow.
The schema for the tMSSqlSP looks like:
Column Db Column
entityTIN EntityTIN (IN)
qtdDoc QtdDoc (IN)
nextMsg NextMsg (OUT)
nextDoc NextDoc (OUT)
The only global variable tMSSqlSP has is an error message, and I tried checking the "Is function" box and setting "Return result in" to nextMsg, but trying to use this variable on tJava results in compilation errors.
Any idea how I would go about accessing these values explicitly?
EDIT: Here's a screenshot of this section of the job. The tLogRow connected to the tMSSqlSPprints correctly the values of the two input variables and the two output variables, but the two deactivated components on the right are only able to see null values when connected.

You can link your tMSSqlSP component to a tSetGlobalVar, and add 2 global variables to it (NextMsg and NextDoc) that take their values from the column of your input flow (rowX.column).
You can then reference them in the next subjob by referencing them in a tJava like so : (String)globalMap.get("NextMsg")
If you need to process them in the same subjob as tMSSqlSP, you can instead connect tMSSqlSP to a tJavaFlex or a tJavaRow (as tJava doesn't handle input main flows) and just use something like row18.NextMsg.

Related

Crystal Reports Pass database fields as parameter for Stored Procedure

I have a Stored Procedure/SQL function that makes calculations on a specific record returning 0.00 or another DEC value. It takes the record's primary key as a parameter.
I want to implement this function/Stored procedure in Crystal Reports by passing the primary key database field for each individual record. However, when I try to do this, it requires me to manually input the id. The crystal report that I implement is grouped by the id so that there'll be a report for each record.
Is there a way I can pass a database field as a parameter for a Stored Procedure or a SQL function? Is there something similar I can use?
An alternative approach is to insert a subreport using the SP as its data source into the Group Header section. Pass the ID as the subreport link, so it gets used as the SP parameter.
If you need the returned value in main report calculations, use a subreport formula to load the value into a Shared variable so it is accessible to main report formulas.
Another option is to use a Crystal Reports UFL (User Function Library). Ken Hamady maintains a list of UFLs here. At least one of them provides a function that allows you to call a dynamic SQL statement and return a value.
I can't seem to edit a comment to include code, so I'm posting as a new answer to address your new question:
In the subreport, use a formula to declare and set the value of a shared variable. For example:
Shared numbervar CalcResult := {SP_Column_Providing_The_Result};
In the Main Report, in a section BELOW the subreport, simply declare the same shared variable. And use it. It will return the value from the subreport.
If I've understood you correctly, you want to execute some code (a stored procedure or function) which uses the value of a column as the input to the code, and you want to do that for multiple rows at once.
If you write the code as a user defined function (ideally an inline table valued function), which is sort of like a view that takes a parameter, then you can use cross apply or outer apply to execute the code for each row.
Here's a simple example. Suppose I have a block of code written as a user defined function. It takes an integer input parameter and just adds one to the input parameter:
create or alter function MyFunction(#MyParam int) returns table as
return
(
select #MyParam + 1 as MyResult
);
go
Because this function returns a table, I get the result by selecting from it, just like selecting from a regular table or view, like this:
select MyResult from MyFunction(68);
-- returns a result set with a single row and column, with a value of 69
But the input parameter value can also come from values in a column. We provide the value for each row by cross applying the function to the table, because "cross apply" means "run this function for each row". Suppose I have some table with 2 rows in it:
create table MyTable(i int primary key);
go
insert MyTable(i) values (1), (2);
I want to run my function against all of the values of i in the table. I do this using cross apply, and I pass the name of the column as the input parameter:
select f.MyResult
from dbo.MyTable t
cross apply dbo.MyFunction(t.i) f;
The above code returns the following result set:
MyResult
2
3

Pass array as query parameter in Postman

I am trying to pass an array as query parameter in Postman.
I am calling DELETE method to delete a user from list of databases. It is expecting list of database names as array in the query parameter. When I pass as given below, I am getting error.
{"code":2,"message":"data_services must be an array and not empty"}
Please let me know, how can I pass an array as query parameter in Postman.
You need to create 2 keys with the same name and add postfix []
You can specify the parameter key multiple times with different values.
Don't use square brackets or numbers like an array in code.
This will result in a query string like so:
?data_services=somename&data_services=anothername
I mis-read the DELETE method. It was expecting array of databases in the body of the Http body section, instead of on query parameter section. I provided the array as given below and it got succeeded.
The below is the way, I passed array to Http request in the body section.
can you check below link it is useful for you
https://medium.com/#darilldrems/how-to-send-arrays-with-get-or-post-request-in-postman-f87ca70b154e

How to retrieve a parameter value that's not set in the report?

I'm working in report builder, calling a stored procedure that has a parameter that, when null, sets itself to a certain value. I want to display what this parameter is set to on the report. From experimenting, Report Builder's parameter collection only shows the parameter as it is sent from the report.
Alternatives that I've considered but can't get to work or are sub-optimal:
Adding the parameter to the select statement. The main drawback is this won't display a value if there are no results.
Using a return value or output parameter. There doesn't seem to be a way to do this.
Re-creating the "null" logic in the stored procedure. The correct output is displayed but this is a code fork.
How can I display this value? Is there a way to show a return value or output value?
You could change the procedure to return the parameter value in a UNION ALL select so that a row with the parameter value will always be returned. That row could have NULL for all the other columns so that you can filter it out in the rest of the report.
Another possibility is to add a second dataset to the report that does nothing but get the value of the parameter based on what you pass. That, however, is also a sort of code fork. The fork could be mitigated, however, by putting it in a UDF, and resourcing the same UDF in both datasets.
Yet another possibility is to replicate the logic of populating the parameter in a Custom Code block in the report. However, that is also a code fork.
I've never worked in Report Builder interface but I do have quite a bit of experience building reports in BIDS/VS... There it's a simple matter of setting the parameter default, in the rdl, to match the default in the stored procedure.

Eiffel sqlite call with extra parameters

I have copied some code from an example for accessing an sqlite database. It uses an agent to get the returned rows:
check_db (input_line: STRING)
local
df_db: SQLITE_DATABASE
df_db_query: SQLITE_QUERY_STATEMENT
test_val: STRING
do
test_val := "whatever"
create df_db.make_open_read_write ("Large.db")
create df_db_query.make ("SELECT * FROM test_table WHERE test_val =%
% :TEST_VAL%
% ;", df_db)
check df_db_query_is_compiled: df_db_query.is_compiled
end
df_db_query.execute_with_arguments (agent (returned_row: SQLITE_RESULT_ROW): BOOLEAN
do
if returned_row.is_null (1) then
insert_into_db
end
end,
<< create {SQLITE_STRING_ARG}.make (":TEST_VAL", test_val) >>)
end -- check_db
The problem I have is that I would like to pass input_line to the procedure insert_into_db.
The inline procedure used by execute_with_arguments isn't able to see any variables outside its scope, but I presume there must be a way to pass an extra parameter to it? Everything I have tried simply refuses to compile with syntax errors.
In this case, I simply want to add a database entry if it doesn't already exist, but I can easily see the case where I would want to send the returned row along with some extra data to another procedure, so it must be doable.
As you correctly point out, at the moment, local variables in Eiffel are not automatically passed into inline agents. The solution is to add explicit formal arguments to an inline agent and to pass the corresponding actual arguments to it.
The inline agent from the example can be adapted as follows (the outer context with the argument input_line is omitted for brevity):
agent (returned_row: SQLITE_RESULT_ROW; s: STRING): BOOLEAN
do
-- `s` is attached to `input_line` here.
if returned_row.is_null (1) then
insert_into_db
end
end (?, input_line)
In addition to the formal argument s that will get the value of input_line, you can see an explicit list of actual arguments (?, input_line). The question mark denotes an open argument, that will be passed to the agent by execute_with_arguments as before. input_line stands for a closed argument.
When the list has no closed arguments, as in the original code, it can be omitted. However, one could have written (?) after the keyword end of the inline agent in the original code to be absolutely explicit.

SSRS parameter returns a data type that is not valid

I got the Tumbleweed badge for this question.... :)
I've moved on a little from the original question but still looking at using internal/hidden parameters, this time passing to another report which runs a stored procedure (which sends an email).
The main report (report A) has a parameter called StudentCourses (originally called ReportParameter1) which I have tried both as Hidden or Internal, and currently has ticked Allow blank value and Allow multiple values.
(Its default value is a field from the result of a query, which shows the courses a student is enrolled on).
Action for my textbox no longer goes to URL (to open PHP form) but now uses Go to report to call report B. Under action options I've added two parameters; StudNetworkID and StudCourses. The number of courses can vary from 2 to 5.
The new report (report B) has two parameters also called StudNetworkID and StudCourses; both are Hidden and StudCourses has ticked Allow blank value. [All parameters are text, btw].
If Report A StudCourses is set to =Parameters!StudentCourses.Value(0) then the first course is shown on Report B. So far so good.
If Report B StudCourses is set to Allow multiple values, then Report B shows #Error and the Warning description given is "[rsInvalidExpressionDataType] The Value expression used in textrun ‘Textbox3.Paragraphs[0].TextRuns[0]’ returned a data type that is not valid."
If Report B StudCourses is set to NOT Allow multiple values and Report A StudCourses value is set to [#StudentCourses] then Report B shows the text "[#StudentCourses]".
If Report B StudCourses is set to Allow multiple values again, then I get the same invalid data type error as before.
Having turned off Allow multiple values on Report B to avoid the #Error issue...
Setting Report A StudCourses to =Parameters!StudentCourses.Value(0) & Parameters!StudentCourses.Value(1) then Report B shows course 1 and course 2 on one line. OK so far.
However, setting Report A StudCourses to =Parameters!StudentCourses.Value(0) & Parameters!StudentCourses.Value(1) & Parameters!StudentCourses.Value(2) gives me a runtime error that the Index was outside the bounds of the array (because there are currently only two courses). On clicking the textbox, Report B just says "The 'StudCourses' parameter is missing a value".
OK...
I turned off Allow multiple values on Report A StudentCourses parameter (the one holding the result from the query) and for the Go to report parameter StudCourses I added the other values, so eventually had value(0) to value(4), the result was interesting. For each parameter value used it gave me a letter from the first course on Report B. Hence when I included up to value(4) it gave me the first five letters of course one!
Yep, ok, this is because it is no longer reading multiple values and so specifying a number just returns the letter from that position.
SO...
How do I allow for up to 5 courses to be passed over???
What follows below is the original question
I have a small report designed in Visual Studio that displays courses that a student is enrolled on. The number of courses can vary from 2 to 5, depending on the student.
Also on the report is a text box, which when clicked will action a url to open a PHP form.
I have worked out how to pass the user id to this PHP form but, if possible, I would also like to pass the course titles.
If I use internal report parameters* I can add these to the url, like this:
="http://myurl/webform.php?param=" & Mid(User!UserID,InStrRev(User!UserID,"\")+1)
& Parameters!ReportParameter1.Value(0)
& Parameters!ReportParameter1.Value(1)
& Parameters!ReportParameter1.Value(2)
& Parameters!ReportParameter1.Value(3)
& Parameters!ReportParameter1.Value(4)
but unfortunately I get the runtime error "The Hyperlink expression for the text box 'Textbox7' contains an error: Index was outside the bounds of the array."
If I just put the first two report parameters it works fine.
I tried using parameter count, e.g. iif(Parameters!ReportParameter1.Count > 2, Parameters!ReportParameter1.Value(2), " "), but I still get the same error.
Please can someone show me how to get around this runtime error, or suggest another way to do this?
Thanks
PS * Report Parameters set up as Text, Allow blank value, Allow multiple values, Internal, Available Values = None, Default Values = Get values from a query; Value field = course title.

Resources