Using Parameters in SSRS with LIKE operator - sql-server

I am trying to create a report that has a list of various product groups as parameters. When selecting each group, a list of those related products should appear. I am currently getting a blank table.
The results for this product group display when i execute the query.
I have the list of parameters and values as follows:
i'm struggling to see where I have gone wrong, when i preview the report, I can select each parameter, but get an empty table in the report. I expect the way I have given each parameter a value may be the problem, but cannot figure it out.
This is the query in the report.
DECLARE #ProductCode VARCHAR(12)
SELECT STRC_CODE, STRC_DESC FROM DeFactoUser.F_ST_Products
WHERE STRC_CODE LIKE #ProductCode
I am using Visual Studio Data Tools 2012 to build the report.
If anyone could give me a clue, that would be greatly appreciated.

It doesn't work without the quotes. I thought the quotes and wildcard
would be necessary to allow the LIKE operator to work.
First of all you don't need to use quotes, I tried to reproduce it right now and it works without quotes:
Second, the query that SSRS sends to server looks like this:
exec sp_executesql N'select model
from [dbo].[cars]
where model like #car',N'#car nvarchar(3)',#car=N'ca%'
So the only thing it changes respect to your code is parameter type, it always declares it as unicode, i.e. nvarchar(...), so maybe it make sense to try in SSMS your code with parameter type changed to nvarchar(12):
declare ProductCode nvarchar(5) = N'PA.A%'
Try to execute it in SSMS and see if it returns smth or not

Related

SSRS How to see multi value parameter in subscription

I tried to get value from query or to specify values, as soon as the parameter is multi value i can't see the data when i'm trying to make my subscription.
my request looks like :
select id from employee where canal in(#canal)
what should i do, i'm totally stuck,
when i did research i saw data driven subscription but i don't have access to it apparently, don't know if that help
I'll start by saying sorry this isn't a pleasant answer. You've run into a limitation with the built-in functionality. Thankfully there are workarounds.
The problem is that you can only pass 1 value into the data-driven subscription. So you have use a comma-separated list and get the query/report to parse out the values.
If you have or can create a Split function in your database, that is a good option. This would be a table-valued user defined function and there are some easy to find examples already. Also this function is generally good to have for other use cases anyway. With this your SQL would read:
where canal in Split(#canal)
SSRS works really well with SQL Server, but when you use an ODBC connection, the parameter support is limited. You can use the same multi-value parameter workaround that is required in those cases.
In the Dataset properties > parameters tab, use an expression like this to combine the values into a single comma-separated string surrounded by commas.
="," + Join(Parameters!canal.Value, ",") + ","
The SQL would look like this:
where # like '%,' + canal + ',%'
Basically, this searches row-by-row for values that are contained in the string.
In either case, the query in your data-driven subscription settings will need to return the comma-separated string. Then you can select that column in the report parameters value field. Hope this helps!

Procedure not running in toad asking for the variable

I'm using TOAD for Oracle. I'm trying to execute a stored procedure with two parameters - one IN and one OUT. It looks like this:
PROCEDURE get_stuff (
parm_1 IN VARCHAR2,
parm_2 OUT currefcursor)
In the SQL Editor window in TOAD, I've tried various things to no avail. I'm sure this is something simple that I'm missing, 'cause I've tried all sorts of things I've seen in other solutions here at Experts Exchange, but can't get past various errors. Here's what I think should work from what I've seen here:
var p1 VARCHAR2 := 'some text';
var p2 currefcursor;
EXEC get_stuff( :p1, :p2 );
When I run this, though, the SQL Editor pops up a window titled 'Variables' that appears to be looking for a value. No matter whether I put something in the 'Value' textbox or not, when I click OK, it says:
ORA-00900: invalid SQL statement
and highlights the 'var' in front of p1.
Please tell me what I'm missing!
Status Solved Priority Medium Security Public Views 21999
As the second parameter is OUT, you have to declare the variable which will accept that value. Here's how; I don't know what currefcursor type is - I guess you do.
declare
l_out currefcursor;
begin
get_stuff(:p1, l_out);
end;
/
A simple option to view the result would be this: put this code into the editor and run it as a script; the result will be displayed in the Script Output tab.
variable l_out currefcursor
exec get_stuff(:p1, :l_out);
print l_out
Or, you could even create a wrapper function which returns cursor, and then select from it:
create or replace function f_get_stuff(p1 in number)
return currefcursor
is
l_out currefcursor;
begin
get_stuff(p1, l_out);
return l_out;
end;
/
select f_get_stuff(:p1) from dual;
You can use Toad to execute without writing the execution harness yourself as well. Here is one method using the Schema Browser. Select your object and right-click > Execute.
You are presented with a dialog asking for your input parameters. Set your inputs and you can see the generated execution harness below. You can also use this generated code as an educational guide to see one method of writing the code yourself.
Click OK and your function/procedure is executed and results are shown.

Grouping tablix by Paramater is SSRS (#Error) and automatically adding (0) when selected in expression

I hope this is not a stupid question, but I have searched everywhere and have tried everything.
I have a dashboard and would like to group the tablix (The dashboard is inside the tablix) by one of the Parameters (Consultant). There are a few Data sets(queries) in the report and all of the Parameters are filtered with IN in the where clause.
The problem I have is that when I go to the row group properties and select the Parameter in the expression, then it automatically adds a (0) at the end. If I take the (0) away then I get the error message:
the group expression used in grouping 'Group1' returned a data type
that is not valid
I know the (0) is for getting the first value, but I am using Multi-valued Parameters.
I have tried one thing I found, but unfortunately it didn't work for me (SSRS Group By Parameter).
Edited:
This is to show you that there are multiple Data Sets(Queries) in this report
I have the dashboard in a tablix so that I can group for each Consultant, so when I choose 3 Consultant, I get 3 dashboards.
Expression used:
Then I get this error:
I have also tried using the CStr, but also no luck.
When I add the Parameter in any expression box it automatically put the (0) as below:
But then it doesn't use the parameter as I get an #Error where is should be the Consultant name.
I also used this option for page break but end up with graphs below each other:
This is what happens to the Charts(Sub Reports)
To give you an idea how the dashboard should look for each Consultant.
Regarding the other question I saw. I just tried exactly as they said but also no luck
I hope this isn't too much information. Just trying to help you help me.
Thank you!
UPDATE:
Parameter Properties:
Have you tried using the list tool to separate the sub reports by Consultant? A list acts like a container and will create whatever is inside for your grouping. You should also be able to apply a parameter to the list for filtering.

Cakephp mssql Store Procedure with parameters (Invalid cursor state)

I use CakePhp for a little application. In this application I store some store procedures (I use mssql). Now I want to execute theses store procedures and want to use the result set.
If I call a store procedure without any parameters i get want I want without any problems. But when i call another store procedure with parameters i get the error "Invalid cursor state"). I did some research and i understood that there it seemed to be that i execute multiple select because of the result-state.
In CakePhp i call:
This is running without any problems
$res = $db->query("Exec storeProcedureWithoutParams");
Here I get the error with the cursor
$res = $db->query("Exec storeProcedureWithParams 'param1'");
The store procedures are very simple:
CREATE PROCEDURE [dbo].[storeProcedureWithoutParams]
AS
SELECT [u1]
,[u2]
,[u3]
,[u4]
,[u5]
,[u6]
FROM [testdb].[dbo].[test]
CREATE PROCEDURE [dbo].[storeProcedureWithParams]
#test nvarchar(50)
AS
SELECT [u1]
,[u2]
,[u3]
,[u4]
,[u5]
,[u6]
FROM [testdb].[dbo].[test]
where [u6] <> #test
If I execute the both queries directly at the database I get two return. The first one is the result of the select-statement and the second one is the result-set. If I understood it right, is this the problem because i get two results (thats why the cursor-error). BUT I don't know how to solve it and I don't know how to get only the result of the select-statement without the return-state?
Can anybody help me?
Thank you very much!
Greetz
V
Sorry for the late answer, but I'll add it here for testing purposes, as there aren't any full answers for this question.
Not sure 100%, but seems that when there is some kind of message output along the query results, it gives the "invalid cursor state". Adding SET NOCOUNT ON it solved to me.

EF generate result objects for SQL OUTPUT clause

What can I do so that EF becomes aware of the output clause in SPs and generates the result object accordingly?
INSERT INTO goodtable
(token,
ip, long_ip,
) OUTPUT INSERTED.*
VALUES
(#token,
#ip, #long_ip,
);
What I currently do to circumvent this is writing a dummy select, generate the objects and the comment out the dummy select leaving the output. This is not a good solution for a long term run.
Please do not suggest changing the SQL.
Have you tried. when importing the stored procedure into EF, using function import, to add the returns a collection of option.
I've never tried it, but can't see a reason for it not to work.

Resources