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
 Group By

Author  Topic 

laptop545
Starting Member

11 Posts

Posted - 2010-01-13 : 22:17:38
Given a GROUP BY with lots of variables and a need to group by all possible permutations of these variables, how would you do this without writing/running hundreds of queries? E.g. if we're grouping by id, name, and email, we would need to generate the following groupings:



By name

By email

By id

By name, email

By name, id

By email, id

By name, email, id





2b) write sql code to produce all permutations of a set of strings, to enable the column-name lookup and dynamic SQL as you suggested doing (note: I have not tried doing this; and don't know if it is possible. 15-minute limit does not apply.)



2c) how many permutations would we have to run for 12 variables?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-13 : 23:48:49
Please show us what you have so far.

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-14 : 00:10:15
sorry you're not clear. do you mean separate queries or you need to do this conditionally?
Go to Top of Page
   

- Advertisement -