user3543512
user3543512

Reputation: 143

SSRS 2008 use different queries based on parameter value

I have 2 Dataset queries and a parameter called 'database'

If the value for 'database' is 'abc', it should use the statement below

select * from abc.item

Meanwhile, if the value for 'database' is 'cba', it should use this statement

select * from cba.item

Initially, I tried passing in the parameter like this

 select * from ?.item

Of course, that didn't work.

I am using ODBC connection to an iSeries

Upvotes: 1

Views: 1695

Answers (2)

Naveen Kumar
Naveen Kumar

Reputation: 1541

you can also create a common data set for both by writing an expression for connection String

Refer to url http://www.sqlservercurry.com/2011/06/dynamic-connection-string-in-sql-server.html

Upvotes: 0

Henrov
Henrov

Reputation: 1620

I assume that the returned columns are the same for abc and cba?

You have to dynamically build your query:

declare @param as varchar(25)
declare @sql as varchar(2000)

set @param = 'abc'
set @sql = 'select * from ' + @param + '.item'

exec (@sql)

Upvotes: 1

Related Questions