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
4

2 回答 2

0

您需要使用类似这样的方法来调用该过程:

INSERT INTO #temptable
     SELECT * FROM dbo.querySkillsOverall(@ChannelName,@GroupName)
于 2013-10-04T17:12:54.883 回答
0

proc 需要向调用脚本返回一个表才能使 aselect into工作。或者,您可能只需要为您插入表格即可。

于 2013-10-04T16:59:04.750 回答