在存储过程中定义一个输出变量:
create table tablename(
A varchar(1000)
)
insert into tablename values(',c,d,d,e,c,f,')create procedure pr_get
@str varchar(100),
@row int output
as
select * from tablename
select @row=@@rowcount
go
declare @row int
execute pr_get 'c',@row output
select @row

解决方案 »

  1.   

    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS OFF 
    GO
    CREATE  PROCEDURE [dbo].[SelectTest_count]
    @Count int Output AS
    select * from test
    set @Count=(select @@rowcount)GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO--测试
    declare @out int
    exec SelectTest_count @out Output  --加上output
    select @out
      

  2.   

    直接select * from tablename
    在结果集中用getUpdateCount()就可以取到
      

  3.   

    select * from 表 ...
    select @@rowcount
      

  4.   

    return 也可SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS OFF 
    GO
    CREATE  PROCEDURE [dbo].[SelectTest_count]
    select * from test
    return @@rowcountGO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GOdeclare @rc int
    exec @rc = SelectTest_count 
    select @rc
      

  5.   

    但有一个问题,我是分页的,也就set rowcount了的,所以返回的不是真正的记录集,能不能返正真正的记录集的总数?
      

  6.   

    大家对不起了,我想了一个永动机的问题,又要SQL不走完全部数据,又要拿出总记录数,结帖,呵呵