We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

GROUP BY WITH CUBE Issue

Medium Priority
266 Views
Last Modified: 2012-05-11
I am having a problem with a query in SQL Server 2008R2.

 
SELECT T0.CardCode, T2.ItmsGrpNam
FROM OITM T0
INNER JOIN OITB T2 ON T0.ItmsGrpCod=T2.ItmsGrpCod
GROUP BY  T0.CardCode, T2.ItmsGrpNam  WITH CUBE

Open in new window


It yields this result set that looks like this:

CardCode | ItmsGrpNam
BrandX     | BrandX A
 (NULL)    |  BrandX A
BrandX     | BrandX B
 (NULL)    |  BrandX B

I am trying to get this result set:

CardCode | ItmsGrpNam
BrandX     | BrandX A
BrandX     |  BrandX B

OR this one:

CardCode | ItmsGrpNam
BrandX     | BrandX A
(NULL)      |  BrandX B

Can someone show me how to properly structure this query to achieve the desired result? Thanks.


Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Alpesh PatelSolution Architect at TCS (SAFe®Agilist, TOGAF® Foundation, PSM I®, MCP, MCSD)
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.