0
我創建了以下SP並希望將其返回到同一數據庫上的新表的數據輸出。一直試圖使用「SELECT * INTO table FROM」的例子,但沒有運氣。將存儲過程的結果插入到表中
執行此功能的最佳方法是什麼?
我已經包含了我創建的SP供參考。
非常感謝!
USE [phoneview]
GO
/****** Object: StoredProcedure [dbo].[querySkillsOverall] Script Date: 10/4/2013 12:19:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Create date: 11/19/2012
-- Description: gets Skill info for Wallboard
-- =============================================
CREATE PROCEDURE [dbo].[querySkillsOverall]
-- Add the parameters for the stored procedure here
@ChannelName varchar(100),
@GroupName varchar(100)=NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT
ROUND(CAST((SUM(tbl_SkillsLive.Abandoned)*100) as float)/NULLIF((SUM(tbl_SkillsLive.Received)),'0'),1) as 'Abandon %',
ROUND(((SUM(CAST(tbl_SkillsLive.WithinSLA as float))*100)/NULLIF(SUM(CAST(tbl_SkillsLive.Received as float)),'0')),1) as 'Within SLA %',
SUM(Received) as Received,
SUM(Abandoned) as Abandoned,
tbl_Channels.AbnExp,
tbl_Channels.AbnMin,
tbl_Channels.SLAExp,
tbl_Channels.SLAMin,
CASE WHEN SUM(tbl_SkillsLive.Handled) >=1 then (SUM(tbl_SkillsLive.ASA)/SUM(CASE WHEN ASA >0 THEN Handled ELSE NULL END)) Else NULL END as 'AnsTime'
FROM tbl_SkillsLive
LEFT JOIN tbl_Skills on tbl_Skills.Skill_KeyID = tbl_SkillsLive.Skill_KeyID
LEFT JOIN tbl_Skills_Channels_Link ON tbl_Skills_Channels_Link.Skill_KeyID = tbl_Skills.Skill_KeyID
LEFT JOIN tbl_Channels on tbl_Channels.ChannelID = tbl_Skills_Channels_Link.ChannelID
LEFT JOIN tbl_Groups on tbl_Groups.GroupID = tbl_Skills_Channels_Link.GroupID
WHERE tbl_Channels.Name = @ChannelName
AND (@GroupName is NULL OR tbl_Groups.Name = @GroupName)
GROUP BY tbl_Channels.Name,
tbl_Channels.AbnExp,
tbl_Channels.AbnMin,
tbl_Channels.SLAExp,
tbl_Channels.SLAMin
END
GO
使這是一個內嵌表值函數,而不是存儲過程。然後你可以做'SELECT * INTO foo FROM dbo.querySkillsOverall(@ ChannelName,@ GroupName)' –