Hi
Recently (and from help from you guys) I had a query that I now need to add in a filed called oh.deliverydate
This is so our front end system as a date field from which we can select between dates. I have tried to add it in but it then takes out the count levels for OTIF for each sales manager, it totals correctly but does not show the correct figured per sales manager. Could someone advise where I need to add it in with syntax please. Thanks
; With Data As
(
SELECT count(oh.udfSalesOrderOTIF) AS Count
, oh.OrderStatus
, sr.Name
, oh.udfSalesOrderOTIF
FROM dbrderHeader oh
INNER JOIN dbo.SalesRep sr
ON oh.SalesRepID = sr.SalesRepID
GROUP BY oh.OrderStatus
, sr.Name
, oh.udfSalesOrderOTIF
HAVING (oh.OrderStatus = 8)
AND (NOT (COUNT(oh.udfSalesOrderOTIF) IS NULL))
AND (NOT (oh.udfSalesOrderOTIF IS NULL))
), GrandTotal As
(
Select Sum([Count]) As GrandTotal
From Data
)
Select udfSalesOrderOTIF
, Coalesce(Min(Case When Name = 'Bob Banks' Then [Count] End), 0) As [Bob]
, Coalesce(Min(Case When Name = 'Antony Considine' Then [Count] End), 0) As [Antony]
, Coalesce(Min(Case When Name = 'Eddie O''Riordan' Then [Count] End), 0) As [Eddie]
, Coalesce(Min(Case When Name = 'Lawrie Gingel' Then [Count] End), 0) As [Lawrie]
, Coalesce(Min(Case When Name = 'Office' Then [Count] End), 0) As [Office]
, Coalesce(Min(Case When Name = 'Scott Laughton' Then [Count] End), 0) As [Scott]
, Coalesce(Min(Case When Name = 'Ray Cowburn' Then [Count] End), 0) As [Ray]
, Coalesce(Min(Case When Name = 'Lee Heitzman' Then [Count] End), 0) As [Lee]
, Coalesce(Min(Case When Name = 'Administration' Then [Count] End), 0) As [Admin]
, Coalesce(Min(Case When Name = 'Paul Lowery' Then [Count] End), 0) As [Paul]
, Coalesce(Min(Case When Name = 'Group' Then [Count] End), 0) As [Group]
, Sum([Count]) As [Total]
, 100.0 * Sum([count]) / GrandTotal.GrandTotal AS Percentage
From Data
Cross Join GrandTotal
Group By udfSalesOrderOTIF,GrandTotal.GrandTotal
Recently (and from help from you guys) I had a query that I now need to add in a filed called oh.deliverydate
This is so our front end system as a date field from which we can select between dates. I have tried to add it in but it then takes out the count levels for OTIF for each sales manager, it totals correctly but does not show the correct figured per sales manager. Could someone advise where I need to add it in with syntax please. Thanks
; With Data As
(
SELECT count(oh.udfSalesOrderOTIF) AS Count
, oh.OrderStatus
, sr.Name
, oh.udfSalesOrderOTIF
FROM dbrderHeader oh
INNER JOIN dbo.SalesRep sr
ON oh.SalesRepID = sr.SalesRepID
GROUP BY oh.OrderStatus
, sr.Name
, oh.udfSalesOrderOTIF
HAVING (oh.OrderStatus = 8)
AND (NOT (COUNT(oh.udfSalesOrderOTIF) IS NULL))
AND (NOT (oh.udfSalesOrderOTIF IS NULL))
), GrandTotal As
(
Select Sum([Count]) As GrandTotal
From Data
)
Select udfSalesOrderOTIF
, Coalesce(Min(Case When Name = 'Bob Banks' Then [Count] End), 0) As [Bob]
, Coalesce(Min(Case When Name = 'Antony Considine' Then [Count] End), 0) As [Antony]
, Coalesce(Min(Case When Name = 'Eddie O''Riordan' Then [Count] End), 0) As [Eddie]
, Coalesce(Min(Case When Name = 'Lawrie Gingel' Then [Count] End), 0) As [Lawrie]
, Coalesce(Min(Case When Name = 'Office' Then [Count] End), 0) As [Office]
, Coalesce(Min(Case When Name = 'Scott Laughton' Then [Count] End), 0) As [Scott]
, Coalesce(Min(Case When Name = 'Ray Cowburn' Then [Count] End), 0) As [Ray]
, Coalesce(Min(Case When Name = 'Lee Heitzman' Then [Count] End), 0) As [Lee]
, Coalesce(Min(Case When Name = 'Administration' Then [Count] End), 0) As [Admin]
, Coalesce(Min(Case When Name = 'Paul Lowery' Then [Count] End), 0) As [Paul]
, Coalesce(Min(Case When Name = 'Group' Then [Count] End), 0) As [Group]
, Sum([Count]) As [Total]
, 100.0 * Sum([count]) / GrandTotal.GrandTotal AS Percentage
From Data
Cross Join GrandTotal
Group By udfSalesOrderOTIF,GrandTotal.GrandTotal