I am writing the following SQL script, and am encountering the error listed directly below said script:
SELECT
concat(month([sbi].[dtmDelivered]),'-',year([sbi].[dtmDelivered])) as rdate
,o.[strCompanyNodeName]
,sum(sbi.[mnyDollarcost])
,p.[strProductName]
,p.[strProductType]
,o.[strSalesRegionNodeGroup]
,o.[strSalesRegionNodeName]
,concat(o.[strMasterSalesFirstNameNode],' ',o.[strMasterSalesLastNameNode]) AS "Sales_Rep" FROM [sqlSalesBI].[Fact].[uvwReport] as "sbi"
LEFT JOIN [sqlDim].[dbo].[tbldimProduct] as "p" ON [sbi].[intDimProductPrimaryID] = p.intDimProductID
LEFT JOIN [sqlSalesBI].[Dim].[uvwOrgNode] as "o" ON [sbi].[intOrgNodeID] = o.intOrgNodeID
LEFT JOIN [sqlDim].[dbo].[tbldimStatus] as "t" ON [sbi].[intDimStatusID] = t.intDimStatusID
WHERE sbi.intDimStatusID = 5 and sbi.mnyDollarcost >0 and sbi.dtmDelivered >= '2015-01-01 00:00:00.000'
GROUP BY o.strCompanyNodeName
ERROR I RECEIVE WHEN EXECUTING
Msg 8120, Level 16, State 1, Line 3
Column 'sqlSalesBI.Fact.uvwReport.dtmDelivered' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 3
Column 'sqlSalesBI.Fact.uvwReport.dtmDelivered' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What I am ultimately hoping to accomplish is an end table, where the revenue ('mnydollarcost') is summed and grouped by month and year ('rdate'), as well as by company ('strCompanyNodeName').
Here's a table demonstrating what I'd like the outcome to be
rdate strcompanynodename Sum of MnyDollar Cost other columns >>>
----------------------------------------------------------------------------------
7-2017 Chadwick Supply Co. 5100
7-2017 Northeastern Milling 5600
7-2017 Ford Paper 25320
7-2017 Cleveland Paper Co. 1020
8-2017 Chadwick Supply Co. 1200
8-2017 Northeastern Milling 5600
8-2017 Ford Paper 58450
8-2017 Cleveland Paper Co. 1200
I am extremely new to SQL, so thank you for your patience in advance!