muhie
Starting Member
3 Posts |
Posted - 2011-09-22 : 05:31:22
|
SELECT SalesArea, Branch, 'Region', 'Town', 'RepCode', 'Rep', 'Customer', ReportRep, 'Segment', Brand, Pack, 'Calyear', 'CalMonth', InvoiceDate, TradeDay, 'DayName', SUM (QtyInvoiced) AS QtyInvoiced, SUM('HLitre') AS HLitreFROM (SELECT br.SalesArea, br.Branch, dbo.Proper(ac.RegionClass2) AS 'Region', dbo.Proper(ac.Location) AS 'Town', ac.Salesperson AS 'RepCode', dbo.Proper(td.Name) AS 'Rep', dbo.Proper(ac.Name) AS 'Customer', td.ReportRep, dbo.Proper(ac.MicroSegment) AS 'Segment', ds.Brand, ds.Pack, DATEPART(yy, a.InvoiceDate) AS 'Calyear', DATEPART(mm, a.InvoiceDate) AS 'CalMonth', a.InvoiceDate, b.TradeDay, DATENAME(dw, a.InvoiceDate) AS 'DayName', a.QtyInvoiced, a.Volume AS 'HLitre'FROM dbo.vArTrnDetail AS a WITH (nolock) INNER JOIN dbo.Customers AS ac WITH (nolock) ON a.Customer = ac.Customer INNER JOIN dbo.vBranch AS br WITH (nolock) ON ac.Branch = br.Branch INNER JOIN dbo.DimStockCode AS ds WITH (nolock) ON a.StockCode = ds.StockCode LEFT OUTER JOIN dbo.vSalesBudget AS b WITH (nolock) ON b.Area = ac.SalesTeam AND a.InvoiceDate = b.TradeDate LEFT OUTER JOIN dbo.SalesReps AS td ON ac.Salesperson = td.Salesperson AND ac.Branch = td.BranchUNION ALLSELECT 'Distell' AS 'SalesArea', 'ZZ' AS 'Branch', dc.Region, dc.Town, dc.Rep AS 'RepCode', dc.Rep, dc.CustName AS 'Customer', b.ReportRep, dc.Segment, ISNULL(ds.Brand, 'Not Captured') AS 'Brand', ISNULL(ds.Pack, 'Not Captured') AS 'Pack', a.CalYear, a.CalMonth, a.InvoiceDate, td.TradeDay, DATENAME(dw, a.InvoiceDate) AS 'DayName', a.Cases, a.HLitres AS 'HL'FROM dbo.DistellSales AS a INNER JOIN dbo.DistellCustomers AS dc ON a.Customer = dc.CustCode INNER JOIN dbo.DistellReps AS b ON dc.Rep = b.Rep LEFT OUTER JOIN dbo.DimStockCode AS ds ON a.StockCode = ds.StockCode LEFT OUTER JOIN(SELECT DISTINCT TradeDate, LEFT(DATENAME(dw, TradeDate), 3) AS 'dayName', TradeDayFROM dbo.SalesBudget AS td) AS td ON a.InvoiceDate = td.TradeDateWHERE (a.HLitres <> 0)) AS aGROUP BY SalesArea, Branch, Region, Town, RepCode, Rep, Customer, ReportRep, Segment, Brand, Pack, Calyear, CalMonth, InvoiceDate, TradeDay,DayNameError i get is? Msg 8117, Level 16, State 1, Line 3Operand data type varchar is invalid for sum operator. |
|