I have a report and which is coming from database MasterDB. Now I have created a copy of the same database named MasterArchive. I have created parameters for databases to display in dropdown. So, When user select MasterDB from select DataSource dropdown then datasource should change according to selection.
how to change the datasource based on the selection?
Can anyone please guide me how to achieve this.
You can actually write an expression for your connection string by clicking that fx button below the Build button. For example, the expression would be something like:
="Data Source=...;Initial Catalog=" + Parameters!DataSource.Value
As far as I know there is no elegant way of doing this other than using dynamic SQL
So in you Dataset query it might look something like
DECLARE #sql varchar(max)
SET #sql = 'SELECT * FROM ' + QUOTENAME(#datasourceParameter) + '[dbo].[myTable]'
EXEC (#sql)
It's rather clunky but it will work.
There does not appear to be away of editing the datasource, it seems to be set once during report execution even if it's based on a parameter. I did test this briefly but could not get it to work. It might be worth further investigation though as that would be a more elegant solution.
Related
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.
I'm using now SQL Server 2008 R2.
My website shows the report exactly as it is, including the container where the parameters appear (the client prefers it that way).
However, my website solution includes localization (Portuguese, English, Spanish).
I've tried to translate the parameters by creating one parameter for each language, and then show them according the selected one. It didn't work in SSRS 2008. Because I don't know how to find the visibility properties of prompt.
Does anyone know a solution... Or if SQL Server 2012 has solutions for translating parameter's prompt, or conditional visibility?
Thanks.
The only solution I've found so far (SSRS 2008, 2008R2, 2010, 2012) is to break the DRY commandments, and duplicate the reports with language codes as part of the report name (e.g. MyReport_sp.rdl, MyReport_de.rdl, etc) and then place a web service between the client request and the SSRS instance. The web service then has to field the request to the correct report based on a "Culture" parameter passed with the client's request.
This is NOT a good solution, though at least the Culture param is used in localizing the rest of the report as well. We still have hopes that at some future date MS will add prompt localizability and we can rename the report to MyReport.rdl and just have everything actually localized. Hmm, what a concept...
Another workaround would be to just put a number in the prompt for the parameter then prefix the label of each parameter with the localised version by either using "get values from query" or by using the expression builder with a switch statement in the label expression.
For the get values from query option you would have a dataset something like this if you have the translated versions in the query:
SELECT ParamLabel, ParamValue
FROM MyLocalisedParameters
WHERE UserLanguage = #Language
Or like this if not:
SELECT
CASE #Language
WHEN 'pt-PT' THEN 'Selecione Departamento: ' + ParamLabel
WHEN 'es-ES' THEN 'Seleccionar Departamento: ' + ParamLabel
ELSE 'Select Department: ' + ParamLabel
END AS ParamLabel
, ParamValue
FROM MyParametersTable
in both cases creating and assigning the Globals!Language to a Parameter called #Language.
Or if using the expression builder for a hardcoded set of values it would look something like this:
either way the end result would look something like this:
Not perfect but functioning and easier to maintain than several copies of the same report.
If you want it to look a bit tidier then just have the Parameter prompt as only one entry in the parameters list and set it to the default value to avoid repetition on every line.
There is none...
As per connect.microsoft.com, this feature has been requested after SSRS 2005 has been released, and while it is on Microsoft's TODO list, the programmer time to do this has never been allocated, and hence in 2012, SSRS is still not capable of doing that.
Although it's (with much effort) possible to translate everything else, it's not possible to translate the parameter prompt.
There is NO conditional visibility either, visibility of parameters is fixed.
Also, there is no way having SSRS use a supplied language instead of the one set in the browser language settings.
The only thing that you CAN do is write a C# program that loads your XML file, get's the report's parameter name(s) (and possibly the report's name as well), looks them up in a database, and automagically creates N reports for n languages.
Then, you have to redirect your users to the report in their language.
You then only need to write an upload tool, because you won't want to do that by hand.
The other way is to use the ReportViewer control, and re-implement parameter selection.
I think there's CrissCross that tries to do that, but it failed in all but 2 of the reports that I tested.
An evil hack would be:
parametername: babla_language1 / blabla_language2 / blabla_language3 / blabla_language4
and then use jQuery to get that string. do string.split('/')[index_of_language]
and then prey that / is never within "blabla_languageXY"
Edit:
I actually did that. You have to use setInterval to do it, because there is no way to detect change when you select a parameter.
So I'm working with SSRS, and I'm basically migrating reports from Stored-procedures/ASPX pages to straight SSRS, which then displays the output in "report Manager" - about halfway there.
Well, the way I've been going about it(as instructed by boss) is to create these "fake" queries which are fed into the wizard.
They look like this:
exec [dbo].[prc_RPT_Respondent_Answer_By_PID]
#BeginDate = '19001010',
#EndDate = '19001010',
#PID = 'test'
And the above goes into the "Query String" box( ie after you'd Right-clk "Reports" --> "add new report" --> "next" ) .
But I am not sure why we create this dummy query.. Is it because then it would automatically add the Parameters (in the "Report Data" column on left) ?
Why not simply use "Query Builder" ?
Any help appreciatd . Thanks
The only difference between your "fake query" and real query is the parameter values. You need some parameter values to setup the report (i.e. obtain column definition etc), but your users will replace them at run time with the real values.
In some situations calling a stored procedure with a SQL query can perform differently than calling it through the "Stored Procedure" option in SSRS. This usually has to do with the defaults of the connection.
On the other hand, it may just be a habit: "Don't change what isn't broken."
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
Anybody knows? Even an "it isn't possible" answer is a good one : )
Hi there,
To begin with - I'm using SSRS 2008 (not R2), report builder 2.0 and a report model.
I want to create dynamic graphs, i.e., to enable the end-user to decide which graph he wants to see - what are the x and y axes.
I'll try to make it simple - let's say my report model have some properties:
prop1
prop2
prop3
.....
i want to use a report parameter to enable the user to choose which propery he wants to use as the x axis, and another parameter to enable him to choose the y axis.
Populating the available values for the parameters is quite easy.
The problem begins when i want to actually create the report :)
Since the number of available properties is big, I don't think that using iif statments or hidden/visible properties is the right approach.
Any ideas?
Hope I made myself clear, and thanks in advance for any help!
I work in BIDS, so I'm not sure how much of this will transfer to Report Builder, but seeing as you haven't gotten any responses in a couple days.
Can you modify your dataset? Create calculated fields based on the parameter. You can create these in a Report Model, and in BIDS, these can be based on a parameter. Hopefully you can do this in Report Builder. The field might be named something like "AxisX." Within the definition of the field, have an iif statement that will return whichever other field is appropriate based on the parameter.
Calculated fields in Report Builder:
http://msdn.microsoft.com/en-us/library/ms345330.aspx
Hmmm, if this was a requirement I'd probably try and do as much as possible in the query, and make sure it's a simple dataset returned e.g.
IF #param1 = 'something'
SELECT val = somefield,
measure = 'sometext'
FROM x
ELSEIF #param1 = 'another'
SELECT val = anotherfield,
measure = 'anothertext'
FROM x
(The code above won't work; it's just an outline of what a query might look like)