drbxr86044 2011-08-29 19:13
浏览 172
已采纳

存储过程和sqlsrv_num_rows - 游标错误?

Is there a way to use sqlsrv_num_rows() with stored procedures?

Basically when i try to use this function I receive one of these errors, depending on the cursor i supply:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -50 [code] => -50 [2] => This function only works with statements that have static or keyset scrollable cursors. [message] => This function only works with statements that have static or keyset scrollable cursors. ) ) 

or

Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 16954 [code] => 16954 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor. ) [1] => Array ( [0] => 01S02 [SQLSTATE] => 01S02 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Cursor type changed [message] => [Microsoft][SQL Server Native Client 10.0]Cursor type changed ) )

I've spent a bit of time trying to search for a solution to this issue, but no luck.

How can i get the row count from a stored procedure using SqlSrv? Would i have to manually loop through the results and $count++; I would like to avoid that. Or, is there some way I could change the actual stored procedure to include the cursor? I'm not very familiar with cursors, so I don't really know if that is a solution or not.

Thank you in advance!

  • 写回答

1条回答 默认 最新

  • douleijiang8111 2011-08-29 20:38
    关注

    see this: sqlsrv_num_rows() with stored procedures doesn't seem like there is much other than work arounds.

    you could capture the @@ROWCOUNT within the procedure and return it as an OUTPUT parameter.

    CREATE PROCEDURE YourProc
    (
        @param1 int
       ,@param2 varchar(5)
       ,@rowCountOf int OUTPUT
    )
    AS
    
    SELECT * FROM TABLE WHERE ...  --returns result set
    SET @rowCountOf=@@ROWCOUNT     --set output variable to be the row count
    return 0
    GO
    

    or you could use sp_executesql instead as described in the above link.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果