Quantcast
Channel: SQLServerCentral » Reporting Services » Reporting Services » Latest topics
Viewing all articles
Browse latest Browse all 2791

Using dynamic datasets/Pass in table name to use as dataset

$
0
0
I want the source for my reports to be temporary tables created before the report is calledIn other words the report itself does not do the data crunching merely picks up the data in a temp tableThe reason for doing this is because the application generates some very complex SQL with security controlled parameters enforced at the application level. To achieve this I have to pass in the name of the temp table as it will change name constanty, in fact, each time the report is run it will have a different nameI expect this has been done before or maybe there's a better way but I couldn't see much out there about how to do thisThe report parameter 'SpoolID' contains the unique number of the report which equates to the name of the temp tableI couldn't find an easy way to specify a table name based on a parameter, but this worked:EXEC ('SELECT * FROM OpenQuery([.], ''select * FROM mydb.db_owner.Report' +@SpoolID + ''') query')- This makes use of a linked server [.] which is actually the server linked to itself, eg:EXEC sp_addlinkedserver @server='.', @srvproduct='', @provider='SQLOLEDB', @datasrc='SERVERNAME\.'The only reason to use linked servers is that OpenQuery permits a string to be passed which can then be modified with the parameter. Maybe a BaseTable query would work as wellNow when the report is run I can pass in the number of the report and it will pick up the correct source tableNow SSRS behaves a lot more like report writers I've used before :blush:

Viewing all articles
Browse latest Browse all 2791

Trending Articles