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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic Columns and Tables

Author  Topic 

jbreslow
Starting Member

16 Posts

Posted - 2011-08-25 : 18:10:45
Hello,

I would like to create a dynamic/ad-hoc report generator where a user would check one or many checkboxes for data (columns) they would like returned. The data resides in many different tables so not only do the columns that are selected need to be dynamic but also the tables and joins.

What is the best way to do this? Does anybody have an example of this type of query?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-25 : 21:21:46
read this http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jbreslow
Starting Member

16 Posts

Posted - 2011-08-26 : 11:56:25
Thanks for the reply khtan... I read the article and it is a bit over my head and I feel that it doesn't answer my original question. I am still unsure on how to write the dynamic query to join tables. I learn better from looking at actual examples. Great article for reference, once I get started though.

Everywhere I read it says that it is a bad idea to pass table names as a variable. If that is the case then how do I dynamically pull the data from a set of tables based on the columns the user wants returned?
Go to Top of Page

jbreslow
Starting Member

16 Posts

Posted - 2011-08-26 : 13:03:16
Is there a downside to creating a View that holds all the data then querying that?
Go to Top of Page
   

- Advertisement -