Click to See Complete Forum and Search --> : Newbie needs help SQL Statement


Chamark
06-06-2006, 10:05 AM
I am using one SQL (View) to get my sums on various fields. I then use a
second SQL (View) to reference the first View to do my calculations. Is there
a way to combine this all in one SQL View? I want to use the second View and
be able to pass it date range variables from a Web page form.

I am new at this and appreciate your help in advance...

View 1.
SELECT TOP 1000 Site, SUM(NchQty) AS SumOfNchQty, SUM(SchdOpenSecsQty) AS
SumOfSchdOpenSecsQty, SUM(LogOnSecsQty)
AS SumOfLogOnSecsQty, SUM(InAdherenceSecsQty) AS
SumOfInAdherenceSecsQty, SUM(OutOfAdherenceSecsQty) AS
SumOfOutOfAdherenceSecsQty,
SUM(HoldSecsQty) AS SumOfHoldSecsQty, SUM
(TotalHandleTime) AS SumOfTotalHandleTime, SUM(TalkHoldAvailable) AS
SumOfTalkHoldAvailable,
[Date]
FROM dbo.[National Call Stats]
WHERE ([Date] >= DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))
GROUP BY Site, [Date]
ORDER BY Site

View 2.
SELECT Site, SumOfInAdherenceSecsQty / (SumOfInAdherenceSecsQty +
SumOfOutOfAdherenceSecsQty) AS Adherence, [Date]
FROM dbo.View1

russell
06-06-2006, 11:29 AM
Create View dbo.CombinedView

AS

SELECT TOP 1000 Site, SUM(NchQty) AS SumOfNchQty,
SUM(SchdOpenSecsQty) AS SumOfSchdOpenSecsQty,
SUM(LogOnSecsQty) AS SumOfLogOnSecsQty,
SUM(InAdherenceSecsQty) AS SumOfInAdherenceSecsQty,
SUM(OutOfAdherenceSecsQty) AS SumOfOutOfAdherenceSecsQty,
SUM(HoldSecsQty) AS SumOfHoldSecsQty,
SUM(TotalHandleTime) AS SumOfTotalHandleTime,
SUM(TalkHoldAvailable) AS SumOfTalkHoldAvailable,
SUM(InAdherenceSecsQty) / (SUM(InAdherenceSecsQty)+SUM(OutOfAdherenceSecsQty)) as adherence
[Date]
FROM dbo.[National Call Stats]
WHERE [Date] >= DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)
GROUP BY
Site, [Date]
GO

Chamark
06-06-2006, 11:45 AM
Thank you. I appreciate your help. This helps. It provides the dates that I need to pass a Web Form variable (i.e. Start Date / End Date) but I need to be able to group the totals per site and if I don't include the date column I can't pass the variable, yet if I include the date I have repeat site names. I know I am probably doing this all wrong. Thanks again for your help