Avatar of cdemott33
Flag for United States of America

asked on 

Help Composing T-SQL Statement

I'm trying to run a report that joins two tables in order to show how many time a 42 inch monitor was order each month.  The t-sql I wrote is not working.  I'm getting an error of "Each GROUP BY expression must contain at least one column that is not an outer reference."  I'm not sure how to fix this error.

Here's my code:
SELECT        Month(cco.arrivalDate) as 'Month of Show', COUNT(cco.componentID) as 'Order Count'
FROM            customComponentsOut AS cco INNER JOIN
                         customComponentsInStock AS cci ON cco.componentID = cci.componentID
WHERE        (cci.type = N'monitor')
AND cci.size = '42'
AND cco.arrivalDate BETWEEN '1/1/2015' AND '12/31/2015'
GROUP BY 'Month of Show'

Open in new window

I want the results to look something like this:

Month of Show | Order Count
January               |        10
February             |       21
March                 |       14
April                    |       33

Etc. etc.

Can someone please fix my code so it works.

Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Jim Horn

8/22/2022 - Mon