Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我可以在select语句中将变量用作列吗?_Asp.net_Sql_Sql Server 2008_Tsql_Stored Procedures - Fatal编程技术网

Asp.net 我可以在select语句中将变量用作列吗?

Asp.net 我可以在select语句中将变量用作列吗?,asp.net,sql,sql-server-2008,tsql,stored-procedures,Asp.net,Sql,Sql Server 2008,Tsql,Stored Procedures,我想从存储过程中选择一个变量,以便在ADO.net中使用ExecuteScalar时获得变量值 我的存储过程是这样的 CREATE PROCEDURE dbo.SPListGetID ( @category varchar(100) ) AS declare @maxListId int set @maxListId=(select max(MaterialId) from tblMaterialLists

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

我的存储过程是这样的

    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
。我应该怎么做才能做到这一点呢?

试试
设置@maxListId=@maxListId+1
而不是
@maxListId=@maxListId+1

尝试
设置@maxListId=@maxListId+1
而不是
@maxListId=@maxListId+1

您需要稍微更改语法

select @maxListId= max(MaterialId) where category =@category and mode='1'

您需要稍微更改一下语法

select @maxListId= max(MaterialId) where category =@category and mode='1'
试一试

返回@maxListId
而不是

select @maxListId
      /* SET NOCOUNT ON */
      RETURN
试一试

返回@maxListId
而不是

select @maxListId
      /* SET NOCOUNT ON */
      RETURN