2017-02-23 4 views
1

私はテンポラリテーブルを持っています。このポピュレートされたテンポラリテーブルを別のストアドプロシージャに渡す必要がありますが、SQLではテンポラリテーブルを別のストアドプロシージャに渡すことはできません(とにかくうまくいけません)。'スカラー変数を指定する必要があります'エラーが発生したストアドプロシージャーから別のストアドプロシージャーにテンポラリテーブルを渡すことはできません。

https://msdn.microsoft.com/en-us/library/bb510489.aspxとしてこれを回避するためにTYPEを作成しましたが、intellisenseはこのユーザー定義型を使用するテーブルがスカラー変数ではないと不平を言っています。

CREATE TYPE TableType AS TABLE 
(
    TheIds INT 
); 

DECLARE @IDsThatNeedToPass AS TableType 


INSERT INTO @IDsThatNeedToPass 
SELECT . . . 
. . . 

EXEC OtherStoredProcedure @IDsThatNeedToPass 

For some reason the EXEC command says that I 'Must declare the scalar variable "@IDsThatNeedToPass"' 

In addition to this, my OtherStoredProcedure cannot find my user-defined type. 

CREATE PROCEDURE [dbo].[OtherStoredProcedure] 
(
    @TheIds TableType READONLY -- Complains that Parameter or variable '@TheIds' has an invalid data type 
) 
... 

何か原因が考えられますか?私はMicrosoft SQL Server Management Studio 2014を使用しています。

答えて

0
Refer below one format of temp tables 

**Table variables (DECLARE @t TABLE)** are visible only to the connection 
that creates it, and are deleted when the batch or stored procedure ends. 

**Local temporary tables (CREATE TABLE #t)** are visible only to the 
connection that creates it, and are deleted when the connection is closed. 

**Global temporary tables (CREATE TABLE ##t)** are visible to everyone, and 
are deleted when all connections that have referenced them have closed. 

**Tempdb permanent tables (USE tempdb CREATE TABLE t)** are visible to 
everyone,and are deleted when the server is restarted. 
関連する問題