0

ExecuteScalar我想从我的存储过程中选择一个变量,以便在 ADO.net 中使用时可以获得变量值。

我的存储过程是这样的

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

这里select @maxListId是不允许的。我应该怎么做才能做到这一点?

4

4 回答 4

2

尝试SET @maxListId=@maxListId+1;代替@maxListId=@maxListId+1;

于 2013-03-06T05:46:06.537 回答
1

您需要稍微更改语法

select @maxListId= max(MaterialId) where category =@category and mode='1'
于 2013-03-06T05:47:25.987 回答
0

尝试

RETURN @maxListId代替

select @maxListId
      /* SET NOCOUNT ON */
      RETURN
于 2013-03-06T06:28:46.510 回答
0
CREATE PROCEDURE dbo.SPListGetID
    (
      @category varchar(100)
    )
    AS
begin
      declare @maxListId int
      select  @maxListId= max(MaterialId) from tblMaterialLists 
                      where category =@category and mode='1'
      set @maxListId=@maxListId+1;

     end
于 2013-03-07T05:01:55.280 回答