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 2012 Forums
 Transact-SQL (2012)
 Grouping sets with identifier

Author  Topic 

Luuk123
Yak Posting Veteran

52 Posts

Posted - 2013-10-31 : 03:48:08
Hi all,

I have a query that generates invoices which checks an input parameter (period) to determine if the grouping is per week/4weeks/month.

I can use three seperate querys, each for one grouping-type, but I'm wondering if there's a way to use one query with a grouping set dependend on the parameter.

Using grouping sets is such a way, but this generates results for all three grouping sets and I can't identify which one is needed.

Does anyone have an idea?

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-31 : 04:04:26
you can use GROUPING_ID to identify different groups

http://technet.microsoft.com/en-us/library/bb510624.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Luuk123
Yak Posting Veteran

52 Posts

Posted - 2013-10-31 : 08:07:48
Thanks, it works!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-31 : 08:28:02
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -