saintedmunds
Technical User
HI
I have two groupby stored procedures which I would like to combine into one.
The result I would like is
ActivitieDate, Salesperson, Interest, AmountOfLeads, AmountOfUnuseable.
Below are the two SP that work
ALTER PROCEDURE dbo.spWebLeadsByDateUnuseable
(@FromDate smalldatetime,
@ToDate smalldatetime)
AS SELECT dbo.tSalesPerson.SalesPerson, COUNT(dbo.tSalesPerson.SalesPersonID) AS AmountOfUnUseable, dbo.tActivities.ActivitieDate
FROM dbo.tContacts INNER JOIN
dbo.tActivities ON dbo.tContacts.ContactID = dbo.tActivities.ContactID LEFT OUTER JOIN
dbo.tSalesPerson ON dbo.tActivities.SalesPersonID = dbo.tSalesPerson.SalesPersonID
WHERE (dbo.tActivities.RegardingID = 11) AND (dbo.tActivities.ActivitieDate BETWEEN CONVERT(DATETIME, @FromDate, 102) AND CONVERT(DATETIME,
@ToDate, 102)) AND (dbo.tContacts.ContactStageID = 5)
GROUP BY dbo.tSalesPerson.SalesPerson, dbo.tActivities.ActivitieDate
and
ALTER PROCEDURE dbo.spWebLeadsByDate
(@FromDate smalldatetime,
@ToDate smalldatetime)
AS
SELECT dbo.tSalesPerson.SalesPerson, COUNT(dbo.tSalesPerson.SalesPersonID) AS AmountOfLeads, dbo.tActivities.ActivitieDate, dbo.tContacts.Interest
FROM dbo.tContacts INNER JOIN
dbo.tActivities ON dbo.tContacts.ContactID = dbo.tActivities.ContactID LEFT OUTER JOIN
dbo.tSalesPerson ON dbo.tActivities.SalesPersonID = dbo.tSalesPerson.SalesPersonID
WHERE (dbo.tActivities.RegardingID = 11) AND (dbo.tActivities.ActivitieDate BETWEEN CONVERT(DATETIME, @FromDate, 102) AND CONVERT(DATETIME,
@ToDate, 102))
GROUP BY dbo.tSalesPerson.SalesPerson, dbo.tContacts.Interest,dbo.tActivities.ActivitieDate
HAVING (NOT (dbo.tContacts.Interest IS NULL))
Any help would be great
Cheers
I have two groupby stored procedures which I would like to combine into one.
The result I would like is
ActivitieDate, Salesperson, Interest, AmountOfLeads, AmountOfUnuseable.
Below are the two SP that work
ALTER PROCEDURE dbo.spWebLeadsByDateUnuseable
(@FromDate smalldatetime,
@ToDate smalldatetime)
AS SELECT dbo.tSalesPerson.SalesPerson, COUNT(dbo.tSalesPerson.SalesPersonID) AS AmountOfUnUseable, dbo.tActivities.ActivitieDate
FROM dbo.tContacts INNER JOIN
dbo.tActivities ON dbo.tContacts.ContactID = dbo.tActivities.ContactID LEFT OUTER JOIN
dbo.tSalesPerson ON dbo.tActivities.SalesPersonID = dbo.tSalesPerson.SalesPersonID
WHERE (dbo.tActivities.RegardingID = 11) AND (dbo.tActivities.ActivitieDate BETWEEN CONVERT(DATETIME, @FromDate, 102) AND CONVERT(DATETIME,
@ToDate, 102)) AND (dbo.tContacts.ContactStageID = 5)
GROUP BY dbo.tSalesPerson.SalesPerson, dbo.tActivities.ActivitieDate
and
ALTER PROCEDURE dbo.spWebLeadsByDate
(@FromDate smalldatetime,
@ToDate smalldatetime)
AS
SELECT dbo.tSalesPerson.SalesPerson, COUNT(dbo.tSalesPerson.SalesPersonID) AS AmountOfLeads, dbo.tActivities.ActivitieDate, dbo.tContacts.Interest
FROM dbo.tContacts INNER JOIN
dbo.tActivities ON dbo.tContacts.ContactID = dbo.tActivities.ContactID LEFT OUTER JOIN
dbo.tSalesPerson ON dbo.tActivities.SalesPersonID = dbo.tSalesPerson.SalesPersonID
WHERE (dbo.tActivities.RegardingID = 11) AND (dbo.tActivities.ActivitieDate BETWEEN CONVERT(DATETIME, @FromDate, 102) AND CONVERT(DATETIME,
@ToDate, 102))
GROUP BY dbo.tSalesPerson.SalesPerson, dbo.tContacts.Interest,dbo.tActivities.ActivitieDate
HAVING (NOT (dbo.tContacts.Interest IS NULL))
Any help would be great
Cheers