SQL Server Error : The active result for the query contains no fields

dldeef67  于 2023-06-28  发布在  其他
关注(0)|答案(1)|浏览(260)

I have a stored procedure to be called from Laravel. It takes 4 inputs and returns a string data. My code:

$getStatus = DB::select(
   "EXEC rsp_GetStatus '" . 
   $flag . 
   "', $id, $this->userId, 
   '" . $country . "', 
   '' "
);

But I'm getting the error:

"The active result for the query contains no fields".

Tried using:SET NOCOUNT ON

$status = DB::select("SET NOCOUNT ON; EXEC rsp_GetStatus ?, ?, ?, ?, ?", 
    [
     $flag, 
     $id,
     $this->userId,
     $country,
     '']);

Still the error . This store procedure checks the id and returns a string value:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[rsp_GetStatus ]  
@param_flag varchar(25),
@param_id bigint,  
@param_userid int, 
@param_countryoforigin varchar(25),
@param_suggestedFlag varchar(25) output  
As  
Begin
Select  @param_suggestedFlag = (select  ...)
 End

Any help would be much appreciated.

kq0g1dla

kq0g1dla1#

As suggested by @AlwaysLearning and @Zhorov declaring the Output variable and fetching it worked. Here is the solution:

$tsql  = "DECLARE @param_suggestedFlag int; SET NOCOUNT ON ; ";
    $tsql .= "EXEC rsp_GetStatus '$flag', $id, @param_suggestedFlag OUTPUT;";
    $tsql .= "SELECT @param_suggestedFlag AS suggestedFlag;";
    $flagData =  DB::select($tsql);
    $suggestedFlag = $flagData[0]->suggestedFlag;

相关问题