Wednesday, March 7, 2012

Dynamic database tables

How does one make a database table dynamic?
I need to have a single report display data from different SQL tables
depending on which client is viewing the data.Here's an example:
1. Run the following static SQL in data pane of report designer: select
name, xtype, crdate from sysobjects
2. Switch to Layout view. This creates the fields in fields window.
3. Go back to the data pane and pase the following query into it: ="select
name, xtype, crdate from " & iif(LCase(User!UserID) = "redmond\ravimu",
"pubs", "northwind") & "..sysobjects where type = 'u'". This will
dynamically source the data from diferent table depending on the current
user.
Notes:
1. Assumption: Table schemas are the same.
2. If the target tables have same number of columna but different names, you
can map each column name to a unique alias as follows: select name As Col1,
xtype As Col2, crdate As Col3 from sysobjects
3. If you have many users, you may want to replace iif() with Switch()
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html
/vafctswitch.asp)
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"jimmy stewart" <jims@.wolfmagick.com> wrote in message
news:u9$uYmQbEHA.3944@.tk2msftngp13.phx.gbl...
> How does one make a database table dynamic?
> I need to have a single report display data from different SQL tables
> depending on which client is viewing the data.
>

No comments:

Post a Comment