Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Grouping sets Expand / Collapse
Author
Message
Posted Wednesday, February 20, 2013 11:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, April 20, 2014 10:08 PM
Points: 30, Visits: 158
Hi All,


how to use the groupingsets to a query having more than 32 columns


plz help out


Post #1422228
Posted Wednesday, February 20, 2013 4:18 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 25, 2014 7:47 PM
Points: 388, Visits: 421
Hello cooljagadeesh,

Can you provide us with a little more detail please? What exactly are you trying to group?
If you're just looking for basic information on grouping, there's a nice article by Craig Freedman.

Link: http://blogs.msdn.com/b/craigfr/archive/2007/10/11/grouping-sets-in-sql-server-2008.aspx
Post #1422350
Posted Thursday, February 21, 2013 11:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, April 20, 2014 10:08 PM
Points: 30, Visits: 158
please take below example


declare @tbl table (Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int,Col7 int,
Col8 int,Col9 int,Col10 int,Col11 int,Col12 int,Col13 int,Col14 int,Col15 int,Col16 int,
Col17 int,Col18 int,Col19 int,Col20 int,Col21 int,Col22 int,Col23 int,Col24 int,Col25 int,
Col26 int,Col27 int,Col28 int,Col29 int,Col30 int,Col31 int,Col32 int,Col33 int,col34 int)


insert @tbl
select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 10,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 20,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 30,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 40,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34





select SUM(Col1) Total,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,
Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30 from @tbl
group by
grouping sets ((),(Col1,Col2),(Col1,Col2,Col3),(Col1,Col2,Col3,Col4),(Col1,Col2,Col3,Col4,COL5),
(Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,
Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30,col31,col32,col33))

plz check

after executing above query its giving error

plz lookinto my issue

"Msg 10706, Level 16, State 1, Line 27
Too many expressions are specified in the GROUP BY clause. The maximum number is 32 when grouping sets are supplied."



Post #1422732
Posted Friday, February 22, 2013 8:09 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, April 20, 2014 10:08 PM
Points: 30, Visits: 158
plz help out dis
Post #1423311
Posted Sunday, February 24, 2013 5:48 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 25, 2014 7:47 PM
Points: 388, Visits: 421
This is probably the error message you are receiving, correct?

Msg 10706, Level 16, State 1, Line 27
Too many expressions are specified in the GROUP BY clause. The maximum number is 32 when grouping sets are supplied.


For a GROUP BY clause that uses ROLLUP, CUBE, or GROUPING SETS, the maximum number of expressions is 32. You will have to remove one of the grouping sets to get the query to finish successfully. Here is a link on GROUPING. http://msdn.microsoft.com/en-us/library/ms177673.aspx

If you drop column 33, the query would run.

declare @tbl table (Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int,Col7 int,
Col8 int,Col9 int,Col10 int,Col11 int,Col12 int,Col13 int,Col14 int,Col15 int,Col16 int,
Col17 int,Col18 int,Col19 int,Col20 int,Col21 int,Col22 int,Col23 int,Col24 int,Col25 int,
Col26 int,Col27 int,Col28 int,Col29 int,Col30 int,Col31 int,Col32 int,Col33 int,col34 int)


insert @tbl
select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 10,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 20,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 30,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
union
select 40,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34

--SELECT * FROM @tbl AS t



select SUM(Col1) Total,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,
Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30 from @tbl
group by
grouping sets ( (),(Col1,Col2),(Col1,Col2,Col3),(Col1,Col2,Col3,Col4),(Col1,Col2,Col3,Col4,COL5),
(Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,
Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30,col31,col32))

Post #1423451
Posted Monday, February 25, 2013 10:08 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, November 21, 2014 12:57 PM
Points: 546, Visits: 1,062
Maybe consider vertical partitioning and recreate in a view?
Post #1423680
Posted Sunday, March 3, 2013 8:01 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, April 20, 2014 10:08 PM
Points: 30, Visits: 158
can u write a query plz plz
Post #1426062
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse