2011-11-24 5 views
10

をsp_executesqlを私は、動的クエリを持っている私は、次のコードを使用しますが、出力パラメータがnullリターン2つの出力パラメータは

それを解決する方法
declare @query nvarchar(max); 
declare @result int; 
declare @type int 
declare @mainVarcharLength int; 

set @query = 'select count(*) , Type_Code from Customers WHERE Customers.Cust_Name = ''CUSTOMER 99'' ' 
set @query = @query + ' and Cus_Is_Active = 1 Group BY Type_Code'; 
select @query 

EXEC sp_executesql @query, N'@result int OUTPUT, @type int OUTPUT', @result, @type 

select @result 
select @type 

を返し、そしてどのように複数に合格することから、二つの出力パラメータを取得したいです出力パラメータ

答えて

14

出力に何が割り当てられているかを記述する必要があります。

set @query = 'select @result=count(*), @type=Type_Code from Customers ....'

次いでOUTPUTと出力を飾ります。

EXEC sp_executesql @query, 
    N'@result int OUTPUT, @type int OUTPUT', 
    @result OUTPUT, 
    @type OUTPUT 

(あなたはまた、入力として''CUSTOMER 99''を渡すことができます)

関連する問題