safari7391
Programmer
Stored Procedures
SQL Server 2000
I am new to stored procedures, but need to create a stored procedure to increase the performance of a report.
Is it possible to take the following 3 views and place them in a stored procedure? If so how?
View3 reference view2, view2 reference view1 and view1 reference 2 table and 1 view.
(View1)
CREATE VIEW dbo._Daily_Metrics
AS
SELECT TOP 100 PERCENT dbo.dagent.row_date, dbo._Agt_Info.item_type, dbo._Agt_Info.Agt_Name_sy AS Agt_Name, dbo._Agt_Info.Log_ID_sy AS logid,
dbo.dagent.split, dbo._Agt_Info.Sprvr_Name, dbo._Agt_Info.Mgr_Name, dbo._Agt_Info.Grp_Mgr_Name, dbo._Agt_Info.Dir_Name,
dbo._Agt_Info.Location_Name_sy AS Loc_Name, dbo.dagent.acd, dbo.dagent.acdcalls, dbo.dagent.acdtime,
dbo.dagent.acwtime + dbo.dagent.acdtime + dbo.dagent.holdtime AS handle_time, dbo.dagent.acwtime, dbo.dagent.holdtime,
dbo.dagent.acwoutcalls + dbo.dagent.auxoutcalls AS outbound_calls, dbo.dagent.acwouttime + dbo.dagent.auxouttime AS outbound_call_time,
dbo.dagent.ti_auxtime, dbo.dagent.ti_stafftime, s53f.Call_Grouping.Segment, s53f.Call_Grouping.Market, s53f.Call_Grouping.Call_Type
FROM dbo.dagent LEFT OUTER JOIN
s53f.Call_Grouping ON dbo.dagent.split = s53f.Call_Grouping.Grp_Nbr RIGHT OUTER JOIN
dbo._Agt_Info ON dbo.dagent.logid = dbo._Agt_Info.Log_ID_sy
WHERE (dbo.dagent.split IN ('499', '120', '177', '12', '33', '54', '15', '14', '11', '13', '233', '231', '230', '123', '155', '287', '50', '73', '18', '20', '47', '51', '52', '53',
'60', '70', '2', '72', '101', '103', '110', '71', '289', '513'))
(View2)
CREATE VIEW dbo.Agt_DlyChDat_CalTyp_Sum
AS
SELECT TOP 100 PERCENT row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, acd, SUM(acdcalls)
AS Sum_acdcalls, SUM(acdtime) AS Sum_acdtime, SUM(handle_time) AS Sum_handle_time, SUM(acwtime) AS Sum_acwtime, SUM(holdtime)
AS Sum_holdtime, SUM(outbound_calls) AS Sum_outbound_calls, SUM(outbound_call_time) AS Sum_outbound_call_time, SUM(ti_auxtime)
AS Sum_ti_auxtime, SUM(ti_stafftime) AS Sum_ti_stafftime, Segment, Market, Call_Type
FROM dbo._Daily_Metrics
GROUP BY row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, acd, Segment, Market, Call_Type
(View3)
CREATE VIEW dbo.Agt_DlyChDat_CalTyp_Sum_Avg
AS
SELECT TOP 100 PERCENT row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, Sum_acdcalls, Sum_acdtime,
CASE WHEN [sum_acdtime] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_acdtime / Sum_acdcalls) END AS Avg_Talk_Time, Sum_handle_time, CASE WHEN [Sum_handle_time] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_handle_time / Sum_acdcalls) END AS Avg_Handled_Time, Sum_acwtime, CASE WHEN [Sum_acwtime] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_acwtime / Sum_acdcalls) END AS Avg_Call_Work_Time, Sum_holdtime, Sum_outbound_calls,
Sum_outbound_call_time, Sum_ti_auxtime, Sum_ti_stafftime, Segment, Market, Call_Type
FROM dbo.Agt_DlyChDat_CalTyp_Sum
GROUP BY row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, Sum_acdcalls, Sum_acdtime, Sum_handle_time,
Sum_acwtime, Sum_holdtime, Sum_outbound_calls, Sum_outbound_call_time, Sum_ti_auxtime, Sum_ti_stafftime, Segment, Market, Call_Type
ORDER BY row_date DESC
SQL Server 2000
I am new to stored procedures, but need to create a stored procedure to increase the performance of a report.
Is it possible to take the following 3 views and place them in a stored procedure? If so how?
View3 reference view2, view2 reference view1 and view1 reference 2 table and 1 view.
(View1)
CREATE VIEW dbo._Daily_Metrics
AS
SELECT TOP 100 PERCENT dbo.dagent.row_date, dbo._Agt_Info.item_type, dbo._Agt_Info.Agt_Name_sy AS Agt_Name, dbo._Agt_Info.Log_ID_sy AS logid,
dbo.dagent.split, dbo._Agt_Info.Sprvr_Name, dbo._Agt_Info.Mgr_Name, dbo._Agt_Info.Grp_Mgr_Name, dbo._Agt_Info.Dir_Name,
dbo._Agt_Info.Location_Name_sy AS Loc_Name, dbo.dagent.acd, dbo.dagent.acdcalls, dbo.dagent.acdtime,
dbo.dagent.acwtime + dbo.dagent.acdtime + dbo.dagent.holdtime AS handle_time, dbo.dagent.acwtime, dbo.dagent.holdtime,
dbo.dagent.acwoutcalls + dbo.dagent.auxoutcalls AS outbound_calls, dbo.dagent.acwouttime + dbo.dagent.auxouttime AS outbound_call_time,
dbo.dagent.ti_auxtime, dbo.dagent.ti_stafftime, s53f.Call_Grouping.Segment, s53f.Call_Grouping.Market, s53f.Call_Grouping.Call_Type
FROM dbo.dagent LEFT OUTER JOIN
s53f.Call_Grouping ON dbo.dagent.split = s53f.Call_Grouping.Grp_Nbr RIGHT OUTER JOIN
dbo._Agt_Info ON dbo.dagent.logid = dbo._Agt_Info.Log_ID_sy
WHERE (dbo.dagent.split IN ('499', '120', '177', '12', '33', '54', '15', '14', '11', '13', '233', '231', '230', '123', '155', '287', '50', '73', '18', '20', '47', '51', '52', '53',
'60', '70', '2', '72', '101', '103', '110', '71', '289', '513'))
(View2)
CREATE VIEW dbo.Agt_DlyChDat_CalTyp_Sum
AS
SELECT TOP 100 PERCENT row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, acd, SUM(acdcalls)
AS Sum_acdcalls, SUM(acdtime) AS Sum_acdtime, SUM(handle_time) AS Sum_handle_time, SUM(acwtime) AS Sum_acwtime, SUM(holdtime)
AS Sum_holdtime, SUM(outbound_calls) AS Sum_outbound_calls, SUM(outbound_call_time) AS Sum_outbound_call_time, SUM(ti_auxtime)
AS Sum_ti_auxtime, SUM(ti_stafftime) AS Sum_ti_stafftime, Segment, Market, Call_Type
FROM dbo._Daily_Metrics
GROUP BY row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, acd, Segment, Market, Call_Type
(View3)
CREATE VIEW dbo.Agt_DlyChDat_CalTyp_Sum_Avg
AS
SELECT TOP 100 PERCENT row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, Sum_acdcalls, Sum_acdtime,
CASE WHEN [sum_acdtime] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_acdtime / Sum_acdcalls) END AS Avg_Talk_Time, Sum_handle_time, CASE WHEN [Sum_handle_time] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_handle_time / Sum_acdcalls) END AS Avg_Handled_Time, Sum_acwtime, CASE WHEN [Sum_acwtime] = 0 OR
[sum_acdcalls] = 0 THEN 0 ELSE (Sum_acwtime / Sum_acdcalls) END AS Avg_Call_Work_Time, Sum_holdtime, Sum_outbound_calls,
Sum_outbound_call_time, Sum_ti_auxtime, Sum_ti_stafftime, Segment, Market, Call_Type
FROM dbo.Agt_DlyChDat_CalTyp_Sum
GROUP BY row_date, Agt_Name, logid, split, Sprvr_Name, Mgr_Name, Grp_Mgr_Name, Dir_Name, Loc_Name, Sum_acdcalls, Sum_acdtime, Sum_handle_time,
Sum_acwtime, Sum_holdtime, Sum_outbound_calls, Sum_outbound_call_time, Sum_ti_auxtime, Sum_ti_stafftime, Segment, Market, Call_Type
ORDER BY row_date DESC