I've got an ugly database structure - tables are named for fiscal years, as in GL_2011, GL_2012, etc.
I need to allow the user to tell me which fiscal year they want to get data from, then construct the table name, and then execute the query.
I've had some success with building a string assigned to #SQL_QUERY and EXECuting it.. But MS Report Builder seems to get lost in the process and often doesn't populate my fields in the dataset. Other times I get erratic errors where I am trying to piece the query together.
Simple Example:
DECLARE #SQL_QUERY VARCHAR(MAX);
SET #SQL_QUERY = 'SELECT ITEM_1, ITEM_2 FROM ' + 'GL_' + CAST(#FISCAL_YEAR_PARM AS VARCHAR(4));
EXEC(#SQL_QUERY)
Here's a suggestion. In order to have SSRS recognize the columns returned by the query, develop a stored procedure that populates a temp table and returns the rows of the temp table. Pass in the fiscal year to determine which db to query (or do it dynamically like you have) to populate the temp table. If you do that, then SSRS knows the columns that will be returned with each call, and will make those available in Builder.
Related
So I have a report with approx 15 datasets.
The report has a date parameter so the user can run for whichever date they want.
Each dataset has sql logic that basically determines:
If #parameter_date does not exist in table
then grab the max date from table < #parameter_date
else
use #parameter date
This works and the report works properly as is.
However, I was trying to see if I can have this sql logic in 1 place (rather than 15 times in the beginning of each dataset query) and store it in a global variable, and pass the proper date into the dataset?
When I look at report properties and "variables" it only looks like I can write an expression, not write sql and return a date based on a query.
I'm sure there is an efficient way of doing this, any help would be appreciated.
Thank you
I've started using SSRS for 6 month and trying to setup a data driven report where the parameter in the report may contain multiple values (customer numbers).
Ive tried to follow the guideline from microsoft:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/3b0f1620-a7ac-4edd-a577-4beef4bddb14/forum-faq-how-to-configure-a-data-driven-subscription-which-get-multivalue-parameters-from-one?forum=sqlreportingservices#3b0f1620-a7ac-4edd-a577-4beef4bddb14
The parameter in the report is setup following the guideline:
uncheck “Allow multiple values” option for the parameter
check "none" on available values
check "none" on default values
The dataset properties for the parameter are setup by adding a filter:
CustomerKey in split(Parameters!Customer.Value, ",")
The report is working fine when there is only one customer in the subscription table but report is empty when the number of customer are more than one.
The data set of the report is not changed. The query of the data subscription is retrieving the data from the SQL table where I have stored the emails and customer number are related. The data tables looks like this:
The tabel is formatted in this way:
The query in the subscription using the table looks like this:
SELECT *
FROM [Table_Archive].[dbo].[ReportSubscription]
where ReportName='CustomerOrder' and Schedule='Every day'
The data retreived to be used in the report is defined by the following query:
select
CustomerLabel AS CustomerLabel
, CustomerKey AS CustomerKey
, SalesItemKey AS SalesItemKey
, SalesItemName AS SalesItemName
, SalesOrderDetailNumberKey
From factview.SalesOrder
where CustomerKey in (#Customer)
I've tried multiple solution on how to specify the customer number in the table (',';"," etc) but without success. I'm quite uncertain if the approach that i'm trying will ever work and i'm having difficulties in finding any good suggestions, hence this post.
I have a dynamic SQL stored procedure returning multiple number of columns for different items.
For example, item1 - 5 columns, item2 - 4 columns
I am thinking of building SSRS reports using that stored procedure hoping to get multiple results.
For example, when click 'item1', it gives you that 5 columns sp can return whist click 'item2', it gives you that 4 columns sp can return
Can SSRS do this? When I use SP as a source for SSRS, it seems that the output is NOT dynamic as it only returns 'item1'
thanks
r
RS will read column metadata from the first result set of the query.
So I suggest you can add a table variable (fixed columns to support all your dynamic results) into your stored procedure, insert the dynamic query result into the table variable, and then select the result from the table variable.
what I did is to create a 'big table' in SSRS and manually create fields sp potentially returns and only display the columns based on the sp outputs by using 'viability' option
the only issue is that you need to manually configure each column to indicate under what circumstance it is supposed to appear
I am working on a stored procedure in MySQL to update a row in a SQL table. What I have is a table where several of the columns are named incrementally. EX: Page_1, Page_2, Page_3....etc.
The data stored in these locations is updated at different times and I have another column to store the number of times the row has been updated. The count variable gets incremented each time the procedure runs and that allows me to utilize it's value in keeping track of where the next update of the data should take place.
From my research I keep finding solutions utilizing "Dynamic SQL." I do not understand how to utilize this to resolve my issue.
I want to pass a variable in to an update statement as the column name.
The code I currently have is as follows.
SET COUNT = COUNT + 1; -- modify count from count column
SET COLUMNLOCATIONVARIABLE = CONCAT('Page_' , COUNT); -- concatenate the count with the column "Prefix"
UPDATE Table
SET COLUMNLOCATIONVARIABLE = INPUTVARIABLE --Use the concatenated statement as the column name and update it with input data
WHERE mainID = INPUTID;
If anyone could explain to me how to pass this variable in as a column name using Dynamic SQL or another solution utilizing non-dynamic SQL I would appreciate it.
Thanks in advance.
This isn't the way to use a database. Create a new table for your Page_* columns, linked to the main table by an identity, with a page number column. Then you can update and include as many pages as you need, addressed by the main identity and the page number.
I am trying to convert one of our most simple reports to Reporting Services.
The original excel report calls several stored procedures using the results of one to structure the next as it drills down through the data.
I currently have 2 datasets both of which call stored procedures.
The first is called GetGlobalCustomers. This populates a resultset which returns the connection info for each database (we have split our database per customer) and returns the fields ID, Name, Customer and Server.
The second is called GetSchedules which needs the Server and Name provided by GetGlobalCustomers to query the correct database.
However I only want to select the Customer by name, not the individual server/name (remembering which customer is on which server and what their database name is nigh impossible).
So I have a parameter called CustomerName, pushed to the top of the parameters list which presents the user the Customer to select first with the value being the ID. I also have two parameters called DBServer and DBName. How do I set DBServer and DBName to be dependent on the Customer selected? There doesn't appear to be a readily apparent means.
I am guessing that it needs to be part of Available Values and Specify Values but I can't figure out how to say "For this customer ID use this database/Name". I think I could by creating two extra datasets which perform a select by id queries for dbserver/dbname, but if I need to do that each time I want to select by parameter I will have dozens of datasets.
You can do that though your datasource with one caveat: you cannot use shared data sources.
The data source connection string can contain parameters in this case. For example:
="Data Source="+ Parameters!P_Environment.Value + ";Initial Catalog=MyDB;"
You are correct in saying that it needs to be part of available values. One possibility is to make the customer reference the full connection string which would be passed to the datasource. So in this case you would have one parameter which presents the customer name as the parameter text and the connection string as value.