【问题标题】:Store Procedure Select into a variable将过程选择存储到变量中
【发布时间】:2010-03-01 00:51:36
【问题描述】:

如何计算表的结果并传递给存储过程变量?

DECLARE @totalrecs varchar
select count(id) from table1

我想要 totalrecs 变量中的计数记录。

【问题讨论】:

    标签: sql sql-server stored-procedures


    【解决方案1】:

    喜欢这个

    --will not count NULLS
    select @totalrecs= count(id) from table1
    
    --will count NULLS
    select @totalrecs= count(*) from table1
    

    【讨论】:

      【解决方案2】:
      
      DECLARE @totalCount Int
      Select @totalCount = count(*) 
      From table1
      
      Exec sp_DoSomething @Var = @totalCount
      

      【讨论】:

        【解决方案3】:
        select @totalrecs= count(id) from table1
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-11-23
          • 1970-01-01
          • 1970-01-01
          • 2016-03-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多