May 2, 2016 at 6:40 am
I am working with XMPIE, but as of right now, the only way to create reports on any given campaign is to generate a view for it using a very complex script. that is designed to take a campaign ID as a parameter. i was wondering if it would be possible to execute a create view statement from SSRS and have some sort of drop-down for the campaign, or if that would be impossible in SSRS. The way I was thinking was to use the campaign table in a parameter with a drop-down set to only use values from the campaign name column, and use that to set the campaign ID parameter, which could be used to generate the required view. If anybody has any better suggestions of how to go about this, I would appreciate any advice that I could get.
May 2, 2016 at 7:26 am
You can execute stored procedures from SSRS. Anything that you can do in a view you could also do in a subquery or temp table inside a stored procedure; a view is just a named query stored in your database. Heck you don't even need a subquery or temp table. You could just have the stored proc return what you need.
The logic to create a view inside a stored procedure would look like this:
CREATE proc x (@id int)
AS
BEGIN
DECLARE @sql varchar(8000) =
'CREATE VIEW xxx AS SELECT x = '+CAST(@id as varchar(10));
EXEC(@sql);
SELECT * FROM xxx;
DROP VIEW xxx;
END
This is, however, wrong for many reasons. You would get the same results by doing this:
CREATE proc x (@id int)
AS
SELECT @id;
(replace my simple SELECT statement with your more complicated query.)
-- Itzik Ben-Gan 2001
May 2, 2016 at 8:00 am
There's no need to create a view from SSRS. A view is simply a named query. You should be creating a stored procedure in the server and call the stored procedure instead of creating the view.
May 2, 2016 at 8:12 am
That is a good point. I should have thought of that .
May 3, 2016 at 8:51 am
So now I am wondering if anyone could post me in the direction of some good information on usig dynamically generated queries in SSRS. The data can have different column names and different amounts of columns based on what campaign the query is given a parameter. I am not even sure if there is a way to do this .
May 3, 2016 at 9:05 am
Steven.Grzybowski (5/3/2016)
So now I am wondering if anyone could post me in the direction of some good information on usig dynamically generated queries in SSRS. The data can have different column names and different amounts of columns based on what campaign the query is given a parameter. I am not even sure if there is a way to do this .
There isn't. SSRS expects a specific number of columns with specific names, which it obtains when you add the dataset. If you add extra columns to the dataset, SSRS will not notice these unless you refresh the dataset. If you remove any columns (this includes renaming, as this would be seen as removing and adding), SSRS will FAIL, as an expected item does not exist.
If you have dynamic columns, my suggestion would be to also return all the columns you need (even if they are full of NULLs), and then only display the columns required on SSRS based on your selection criteria.
You can have a column's visibility dynamically change by right clicking the column and selecting Column Visibility. Select the radio option "Show or hide based on an expression" and then click the fx button to enter your expression.
So, for example, if you only wanted to display a column if the variable Stock had the value "Television", you would put the following:
=iif(Parameters!Stock.Value = "Television", FALSE, TRUE)
Note that FALSE DISPLAYS the column. The value TRUE equates to "Hide this column".
Hope that helps.
Edit: because I can't spell.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply