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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号