2

テーブル変数のコピーを作成しようとしています。

DECLARE @lt_Sections TABLE
(
  teamId SMALLINT NOT NULL
)

DECLARE @lt_tempSections TABLE
(
  teamId SMALLINT NOT NULL
)

-- populate some values in @lt_Sections
-- take a copy of @lt_Sections

SET @lt_tempSections = @lt_Sections

これは私にエラーを与えています:

Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@lt_Sections".

私は何を間違えましたか?

ありがとう、マーク

4

2 に答える 2

4

Set(またはselect)は、テーブル変数ではなくスカラー変数にのみ適用できます。

値を設定する代わりに、挿入を使用する必要があります

DECLARE @lt_Sections TABLE 
    ( 
      teamId SMALLINT NOT NULL 
    ) 

DECLARE @lt_tempSections TABLE 
( 
  teamId SMALLINT NOT NULL 
) 

insert @lt_TempSections(teamId)
select teamId from @lt_sections
于 2010-01-29T11:25:39.653 に答える
2

このようなテーブル変数をコピーすることはできません(実際の/一時的なテーブルと同じように考えてください)。

次のことを行う必要があります。

INSERT @lt_tempSections (teamId)
SELECT teamId FROM @lt_Sections
于 2010-01-29T11:22:26.483 に答える