Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 A Database as a parameter

Author  Topic 

Adam West
Constraint Violating Yak Guru

261 Posts

Posted - 2009-08-06 : 14:46:10
We have a situation where the database name is to be used as a parameter by the user. If they select Database A, it then is used to present the data in the Reporting Services via the SQL.

How does this work? If I take a typical SQL statment:
SELECT SOP10100.DOCDATE, SOP10200.XTNDPRCE, SOP10200.ITEMNMBR, SOP10200.QUANTITY, IV00101.ITEMDESC,
SOP10100.SOPNUMBE, SOP10200.SOPTYPE, SOP10200.SOPNUMBE, IV00101.ITMGEDSC, SOP10100.CUSTNMBR
FROM (SUPPL.dbo.SOP10200 SOP10200 INNER JOIN SUPPL.dbo.IV00101 IV00101 ON SOP10200.ITEMNMBR=IV00101.ITEMNMBR)
INNER JOIN SUPPL.dbo.SOP10100 SOP10100 ON (SOP10200.SOPTYPE=SOP10100.SOPTYPE) AND (SOP10200.SOPNUMBE=SOP10100.SOPNUMBE)

where SUPPL is my database. I have the same tables on a few other databases, because they are Microsoft GP, can I take a parameter fro the user for database and have the SQL work with it?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-06 : 17:24:18
Yes, but it would require dynamic SQL. I wouldn't recommend this especially if you care about performance. Instead, see if you can change the connection string on the fly to hit a different database.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

Adam West
Constraint Violating Yak Guru

261 Posts

Posted - 2009-08-07 : 14:30:46
What I mean is, we have many reports that are being converted over to Reporting Services. These are being then used by an interface, which will list the customers on the left side of a form, underneath this will be all the reports that the customer has.

Then there will be parameters such as dates, department, and also database.

This is because we are a company which has several product groups, lets say medical products, and food products.

They have previously set these product groups as separate databases, but being that we use Great Plains, these databases have the same basic tables.

So a report that I have written that creates a dataset out of say SOP 10100 and SOP10200, has to run for each database.

So how to tell the SSRS that I want this or that database? Depending on what the user selects out of the parameters area.



Go to Top of Page
   

- Advertisement -