December 26, 2008 at 7:27 am
Hi All,
Here is a query I am using that Shows the following records:
CAROLYN
CAROLYN -OPSX
CAROLYN - PICERNE
CAROLYN - VEN
CAROLYN -HMS
CAROLYN -NON
CAROLYN -WSTDL
I want to combine the result into one record that shows the name as 'CAROLYN'.
SELECT
CASE SalesMan1,
SUM(grand_inv_total) as TotalSales,
DATEPART(mm,CONVERT(DATETIME,DateEntered,106)) as Month
FROM Sales WITH (NOLOCK)
WHERE SUBSTRING(DateEntered,1,4) = 2008
AND SalesMan1 <> ''
GROUP BY SalesMan1, DATEPART(mm,CONVERT(DATETIME,DateEntered,106))
ORDER BY SalesMan1, DATEPART(mm,CONVERT(DATETIME,DateEntered,106))
Thank you.
December 26, 2008 at 7:46 am
Duplicate post - please refer to http://www.sqlservercentral.com/Forums/Topic625851-145-1.aspx
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
February 1, 2011 at 4:43 am
SELECT
substring(salesman1, 1, 7),
DATEPART(mm,CONVERT(DATETIME,DateEntered,106)) as Month,
SUM(grand_inv_total) as TotalSales
FROM Sales
WHERE DATEPART(yy,CONVERT(DATETIME,DateEntered,106)) = 2011
AND SalesMan1 <> ''
GROUP BY substring(salesman1, 1, 7), DATEPART(mm,CONVERT(DATETIME,DateEntered,106))
ORDER BY substring(salesman1, 1, 7), DATEPART(mm,CONVERT(DATETIME,DateEntered,106))
/PA
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply