?
Solved

SQL Query

Posted on 2009-02-13
5
Medium Priority
?
185 Views
Last Modified: 2012-05-06
I have the below SQL code.  I added Item.Description, as the client decided they wanted the description too.  I get the below error message:

Msg 8120, Level 16, State 1, Line 1
Column 'Item.Description' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


select Inventory.ItemNumber as Item,
Sum(OnHandQuantity) as Total,
Item.Description as Description
 
from Inventory inner join Item on Inventory.ItemNumber = Item.ItemNumber
where (Inventory.Site = 'OMWHSE' OR Inventory.Site = 'SAWHSE') AND (Item.Type = '900' OR Item.Type = '3112')  
group by Inventory.ItemNumber
order by Inventory.ItemNumber

Open in new window

0
Comment
Question by:bbanis2k
  • 2
  • 2
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 23634716
Between lines 7 & 8 add
Group By item.Description
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 2000 total points
ID: 23634822
actually they already have one group by, so you just need to add description
select Inventory.ItemNumber as Item,
Sum(OnHandQuantity) as Total,
Item.Description as Description
 
from Inventory inner join Item on Inventory.ItemNumber = Item.ItemNumber
where (Inventory.Site = 'OMWHSE' OR Inventory.Site = 'SAWHSE') AND (Item.Type = '900' OR Item.Type = '3112')  
group by Inventory.ItemNumber,Item.Description
order by Inventory.ItemNumber

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
ID: 23634893
True...
0
 

Author Comment

by:bbanis2k
ID: 23634906
Incorrect syntax near 'group'
select Inventory.ItemNumber as Item,
Sum(OnHandQuantity) as Total,
Item.Description as Description
 
from Inventory inner join Item on Inventory.ItemNumber = Item.ItemNumber
where (Inventory.Site = 'OMWHSE' OR Inventory.Site = 'SAWHSE') AND (Item.Type = '900' OR Item.Type = '3112')  
group by Inventory.ItemNumber
group by Item.Description
order by Inventory.ItemNumber

Open in new window

0
 

Author Closing Comment

by:bbanis2k
ID: 31546680
You are awesome!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question