1

我有一些按此顺序调用的存储过程。

在此处输入图像描述

因此,从第一个存储过程开始,importTaxonomy我调用parseXBRL并从parseXBRL我调用createTaxonomyStructure.

但是在这个流程中,当执行最后一个存储过程的代码时,我得到一个错误。

Msg 1087, Level 15, State 2, Line 1 Must declare the table variable "@temporaryTable".

您可以在下面找到此存储过程的前几行代码:

CREATE PROCEDURE createTaxonomyStructure @taxonomy_table nvarchar(max), @debug bit = 0  
AS

DECLARE @statement NVARCHAR(MAX)
DECLARE @temporaryTable TABLE (taxonomyLine NVARCHAR(MAX))      -- declared a temporary table to avoid creating a Dynamic Query with the entire cursor, but just with the temporary table
DECLARE @taxonomyLine NVARCHAR(MAX)     -- variable that will store one line of the taxonomy

    SET @statement = 'INSERT INTO @temporaryTable SELECT taxText FROM ' + @taxonomy_table   -- statement that will import the taxonomy in the temporary table

EXEC sp_executesql @statement           

DECLARE taxonomyCursor CURSOR READ_ONLY FAST_FORWARD FOR        -- read each line in the taxonomy to parse afterwards
    SELECT taxonomyLine
    FROM @temporaryTable

OPEN taxonomyCursor

FETCH NEXT FROM taxonomyCursor INTO @taxonomyLine               -- parsing each taxonomy line and extracting the values from important attributes
WHILE @@FETCH_STATUS = 0
    BEGIN

        DECLARE @id_element NVARCHAR(MAX)
        DECLARE @leaf_element NVARCHAR(MAX)

        SELECT @id_element = (SELECT dbo.extract_IDElement(@taxonomyLine))
        SELECT @leaf_element = (SELECT dbo.extract_IDLeafElement(@taxonomyLine))

        SET @statement = 'UPDATE ' + @taxonomy_table + ' SET fullName = ''' + @id_element + ''', leafName = ''' + @leaf_element + '''';

        EXEC sp_executesql @statement

    END

我确实声明了这个变量,但我仍然得到错误,我不明白为什么。

我怎样才能克服这个错误?

谢谢!

4

1 回答 1

1

错误在这里:

SET @statement = 'INSERT INTO @temporaryTable SELECT taxText FROM ' + @taxonomy_table   -- statement that will import the taxonomy in the temporary table

EXEC sp_executesql @statement 

将其更改为

set @statement = 'select taxText from ' + @taxonomy_table

insert into @temporaryTable
exec sp_executesql @statement

发生错误是因为在执行范围内@statement没有变量 table @temporaryTable

于 2013-10-18T12:13:22.807 回答