如何在SSIS包执行期间查看插入StoredProcedure临时表中的行

时间:2014-06-13 06:53:13

标签: sql sql-server stored-procedures ssis

ALTER PROC [dbo].[StoredProcedure1] (@XMLRows XML)
AS
BEGIN
SET NOCOUNT ON

DECLARE @myTable TABLE
    (
     [FirstName] [nvarchar](50) NULL,
     [LastName] [nvarchar](50) NULL,
     [Gender] [char](1) NULL
    )

    Insert into @myTable
    (
    FirstName ,
    LastName ,
    Gender 
    )
    SELECT distinct
    FirstName
    ,LastName
    ,Coalesce(Gender,'') Gender
    FROM
    (
    SELECT
     items.value (N'FirstName[1]', 'nvarchar(50)') AS [FirstName]
    ,items.value (N'LastName[1]', 'nvarchar(50)') AS [LastName]
    ,items.value (N'Gender[1]', 'char(1)') AS [Gender]
    FROM @ExportData a
            CROSS APPLY XML_File.nodes('MyNode/Employee') AS NodeTable(Specs)
            OUTER APPLY XML_File.nodes('MyNode/Employee/StaffList') AS NodeTable1(items)
            OUTER APPLY XML_File.nodes('MyNode/Employee/OtherDetails') AS NodeTable2(items2)
            OUTER APPLY XML_File.nodes('MyNode/Employee/MoreDetailsHere') AS NodeTable3(items3)
            OUTER APPLY XML_File.nodes('MyNode/EvenMoreDetails') AS NodeTable4(items4)
    )myTable

END

我有上面存储的StoredProcedure,我从SSIS包调用。有什么办法可以在执行包时查看临时表@myTable中插入的行。我正在对一个错误进行故障排除,我希望在我的包执行时确切地看到@myTable中的内容。

1 个答案:

答案 0 :(得分:1)

分开存储过程。在数据库中创建另一个“真实”表。

CREATE TABLE MyTableLog
(
 [FirstName] [nvarchar](50) NULL,
 [LastName] [nvarchar](50) NULL,
 [Gender] [char](1) NULL
)

然后在存储过程执行期间,截断实际表,并使用在sproc期间生成的内容重新填充它

ALTER PROC [dbo].[StoredProcedure1] (@XMLRows XML)
AS
BEGIN
SET NOCOUNT ON

    DECLARE @myTable TABLE (...)

    Insert into @myTable (...)
    SELECT distinct ...


    TRUNCATE TABLE MyTableLog
    INSERT INTO MyTableLog (FirstName, LastName, Gender)
    SELECT FirstName, LastName, Gender FROM @myTable

END

一旦您的SPROC通过SSIS包完成执行,您只需从任何查询窗口查询您的日志表。

SELECT FirstName, LastName, Gender FROM MyTableLog