0

My code:

Group BY 
  GROUPING SETS 
  ( 
        (wmsSponsorEntityName), 
        (wmsSponsorEntityPrimaryRegion), 
        (wmsProjectNameSWP) , 
        ()          
  )

I'm doing this because those three fields repeat and the other two:

w.[P2010]

w.wugCounty

differ for some wmsProjectNameSWP

wmsSponsorEntityName | wmsSponsorEntityPrimaryRegion | wmsProjectNameSWP | w.wugCounty | P2010

ABERNATHY | O | Local groundwater development | LUBBOCK | 808

ABERNATHY | O | Local groundwater development | HALE | 2297

But I receive an error of Incorrect syntax near 'SETS'.

Any guidance would be appreciated.

Community
  • 1
  • 1

1 Answers1

2

GROUPING SETS was introduced in SQL Server 2008. Which means if you are on SQL Server 2005, you will get a syntax error since it doesn't exist.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Greg
  • 3,861
  • 3
  • 23
  • 58
  • OY. Ok. Thanks, Greg. Everything I found online was saying you could do it. Any other ideas on what I could do? – Meagan K Warncke Aug 06 '15 at 13:45
  • Per this URL, you can use combination of UNION ALL and GROUP BY. https://social.msdn.microsoft.com/Forums/en-US/4a588536-deec-459a-9aaf-f2904daf2236/how-to-use-grouping-sets-in-sql-2005?forum=transactsql. If you want assistance with a workaround, I suggest posting the complete query. – Greg Aug 06 '15 at 13:49