rs report design parametrized query for MySQL - mysql

I have a Mysql DB report with visual studio report server and is displaying correctly in report server.
but i want to do a parametrized query and after reading and searching i know the obdc driver cant pass # and i have to use '?' but after trying a lot i cant figured out how to implemented.
I have a #parameter which use a secodn dataset that query the db for usernames
i have my main dataset with the where (user = '?') and in the dataset parameter tab i try putting an expression with the select query for user and try use the actual parameter.
am a little lost here.

got it in my case..., use
where (usernames = ?)
in the query and in the parameters tab of the dataset use Parameter1 as name and in value match it with the created parameter in Parameters

Related

MySQL + SSRS (SQL Server Report Builder) Dataset/Query Parameters not working

I am currently using SQL Server Report Builder 2012 and is connected to my MySQL Database via an ODBC Connector and as far as base report goes, all is well.
However, i can't seem to make the Query/Dataset Parameters to work the way its supposed to be. I have multiple parameters to my query as you can see below (obviously table and column names are removed):
Now the problem is, if i leave the parameters as is (#OfMonth, #OfDay, #OfYear) - SSRS does not seem to bind the actual values passed from the Report Builder's Parameter Object which i am confident to day that i have associated properly. Not even on the preview/query designer.
However, if i change all #XXXX parameters to simple ? placeholders, it magically works. This poses as issue specially with queries that have multiple parameters.
This is the Report Builder's screenshot of my Work in Progress:
i have no issues defining the 3 Parameter object under the Parameter Node. However, if i try to bind them under Dataset Properties with specific #XXXXX placeholders, it doesn't work, and the report fails to generate data. But if i replace all #XXXXX with ? (all of them are just ?, therefore duplicates), the parameter gets passed and the report loads.
For ODBC connections, you do need to use a ? instead of named variables.
dba.stackexchange | Pass Parameter - SSRS to MySQL
The Parameter Name field on the Dataset Properties should auto-fill with Parameter1, Parameter2,... to match your query but doesn't always seem to work. You can try adding them manually. Since it worked without the name for you, I assume the name doesn't actually matter.
When I would have a parameter used multiple times, I would declare a new one in the query and reuse the new one as #Bacon mentioned:
DECLARE #OfMonth INT
SET #OfMonth = ?
This way you only have to match them once at the beginning of your query.
Use ? as variable in your script, then remember specific order of '?' then using specific order/arrangement of '?' parameters, setup them in the parameter tab after you add the MySQL script.
Ex. Script.
Select * from table1
where column1 = ?
and column2 = ?
When you paste this on the dataset, each '?' will be mapped in the parameter tab.
? Parameter1
? Parameter2
Change this to your own parameters then you're good to go.

How do I use FIND_IN_SET() with a '?' parameter in SSRS Report Builder 3.0?

My SSRS Server is using an ODBC connection to pull data from a MySQL server. I have a query that's making use of the FIND_IN_SET method. My requirements state that the report should provide options for a start and end date parameter and a comma delimited list of "usernames". The start and end date parameters work fine so I've left them out of my sample code for brevity.
When I run the query in MySQL Workbench, I get results. When I run the query in the query designer of Report Builder 3.0, I get results, IF AND ONLY IF, I hard code the value of the parameter being used for the FIND_IN_SET() method. When I try to use a '?' parameter for the value, and paste in the exact same value as when hard coded, I get no results.
This query works in Workbench and the Report Builder's Query Designer:
select pwk.username,
sum(case when pwk.event = '/some-value/' then pwk.count else 0 end)
as order_detail_count
from table pwk
where find_in_set(pwk.username, 'foosername#test.net,foo2#test.com,username#test.org')
This same query returns nothing when I use the '?' parameter and copy/paste the above value when running the query:
select pwk.username,
sum(case when pwk.event = '/some-value/' then pwk.count else 0 end)
as order_detail_count
from table pwk
where find_in_set(pwk.username, ?)
It seems as though the Report Builder is not using the text parameter the way I expect it to but I have no way to determine how to use it "correctly". Has anyone ever run into this problem?
I would expect the results to be identical but that's not the case. Is there a way to use FIND_IN_SET with a text parameter? Or is there some other way to accomplish this? I'm perfectly okay with using something other than FIND_IN_SET if it will work. I tried using IN() but that didn't even work in WorkBench. My users just need to be able to enter multiple usernames as a parameter.
If it's relevant, I'm using a Tablix to display the data.

SSS Report Builder 3.0 Query Parameter - Report Preview

This is a bit strange to me. I am using a SSRS Report Builder 3.0 for creating a report. I have two options: 1. Use a filter linked with report parameter OR 2. Use a query parameter linked with report parameter.
In the first case, the report preview works perfect. I am using a simple query for filter with parameter (#parameter_a) applied on ID column:
Select ID, Name from tbl_Table
But when I use a query parameter linked to the report parameter, the preview is blank. For the query parameter, I use the below query:
SELECT ID, Name FROM tbl_Table WHERE ID = #parameter_a
I am clueless on this. I have also tried keeping a default value or removing it. Refresh/View Report doesn't work either.
PS: I am using MySql ODBC connection. Both options in report work fine when used in a c# application and rendered programatically. Tried re-installing current version, older version as well.
Reading the MySQLCommand documentation, there is reference to an older parameter syntax (not sure what version of MySQL you are using in this scenario).
Using the '#' symbol for paramters is now the preferred approach
although the old pattern of using '?' is still supported. Please be
aware though that using '#' can cause conflicts when user variables
are also used. To help with this situation please see the
documentation on the 'allow user variables' connection string option.
The 'old syntax' connection string option has now been deprecated.
Instead of using #, can you try with ?:
SELECT ID, Name FROM tbl_Table WHERE ID = ?
The order of the parameters used in the query will have to match the order of the SSRS report parameters.

SSRS report is empty

I'm starting to learn Reporting Services. I did my first report that uses a parameterised stored procedure as a data source. Unfortunately even though the procedure works when called from Management Studio, the report comes up empty. The parameter prompt is there and I entered the value that should work. Is there a way to see what's passed to the SQL server (I'm using VS 2012 PRO with SQL Server 2012 Express, So I don't have the SQL Profiler...)? Is there a way to display errors?
OK I finally figured it out. The stored proc. accepted an optional parameter:
#DealID varchar(15) = ''
I was testing it in the where clause like so:
WHERE (#DealID='') OR (SA.Deal_ID = #DealID)
In the parameter settings of the dataset I specified a default value of "" and set it to accept null values and set it's visibility to hidden.
Turns out that even though there was a default value specified, the #DealID parameter was getting null in it. I only realised it when I commented out the WHERE clause and I finally got the data on the report. I solved it by modifying the WHERE like so:
WHERE (#DealID='' or #DealID is null) OR (SA.Deal_ID = #DealID)

DataSet query with Parameters does not work in Report Builder

The following picture shows the query and its result with no variables:
The next one shows the same query with a variable and a different result:
This how the parameter was set just before the query execution:
I have also tried setting the parameter without '' but it produces the same result.
Any clue about what's going on? Any help would be greatly appreciated.
NOTE: The DBMS is MySql
This weird issue is due to the fact that SSRS is connected to MySQL by ODBC connector; therefore, the query parameters should be defined as ? and their names are Parameter1, Parameter2, etc... in order of appearance
Source: http://www.tek-tips.com/viewthread.cfm?qid=1354185
In Report Builder 3.0 you can user parameters in a dataset query using the following syntax:
WHERE sql_column_name = (#Parameter_name_in_ReportBuilder)
Example:
SELECT * from [dbName].[dbo].[TableName]
WHERE Account=(#Parameter1)
Before you can run the report, you need to configure a paramter named Parameter1 (in this example, change this to the name of your parameter) in Dataset Properties - Parameters. The value field should be set to one of the parameters