2013-03-06 95 views
0

我想從存儲過程中選擇一個變量,以便在ADO.net中使用ExecuteScalar時可以獲取變量值。我可以使用變量作爲select語句中的列嗎?

我的存儲過程是這樣的

CREATE PROCEDURE dbo.SPListGetID 
    (
     @category varchar(100) 
    ) 
    AS 
     declare @maxListId int 
     set @maxListId=(select max(MaterialId) from tblMaterialLists 
         where category [email protected] and mode='1') 
     set @[email protected]+1; 
     select @maxListId 
     /* SET NOCOUNT ON */ 
     RETURN 

這裏select @maxListId是不允許的。我該怎麼做才能做到這一點?的@[email protected]+1;

回答

1

0

嘗試

RETURN @maxListId而不是

select @maxListId 
     /* SET NOCOUNT ON */ 
     RETURN 
0
CREATE PROCEDURE dbo.SPListGetID 
    (
     @category varchar(100) 
    ) 
    AS 
begin 
     declare @maxListId int 
     select @maxListId= max(MaterialId) from tblMaterialLists 
         where category [email protected] and mode='1' 
     set @[email protected]+1; 

    end 
相關問題