0

I have this stored procedure with output parameter [IDUtente]:

    ALTER PROCEDURE [dbo].[spGetIDUtente]
    @IDUtente int OUTPUT,
    @Cognome nvarchar(80),
    @Nome nvarchar(50),
    @NomeCompleto nvarchar(150),
    @CF nvarchar(16)
AS
BEGIN
    SET NOCOUNT ON;

    SET @IDUtente = NULL

    -- Recupero l'IDUtente tramite il suo codice fiscale [CF]
    SELECT @IDUtente = IDUtente FROM dbo.Utenti WHERE CF = @CF

How can I call it with Laravel? That's my code:

$id_utente = 0;
$id_utente = DB::select("call spGetIDUtente(?, ?, ?, ?, ?)", [
                    $id_utente,
                    $cognome,
                    $nome,
                    $nome_completo,
                    $cf
        ]);

But it doesn't work, I got this error:

Incorrect syntax near @P1

Mintendo
  • 557
  • 1
  • 8
  • 24
  • Possible duplicate of [How to execute Stored Procedure from Laravel](http://stackoverflow.com/questions/34497063/how-to-execute-stored-procedure-from-laravel) – Benjamin Diaz Mar 26 '17 at 19:05
  • @BenjaminDiaz I just tried in that way, but I receive the same error – Mintendo Mar 27 '17 at 05:48
  • Please, someone can help me? Nobody know how can get output parameter from sql server stored procedure? – Mintendo Mar 27 '17 at 18:51

1 Answers1

0

I resolve myself the problem. This is the way to get output parameter in SQL SERVER with Laravel:

$res = DB::select("
    DECLARE @IDUtente int = 0
    dbo].[spGetIDUtente]
    @IDUtente = @IDUtente OUTPUT,
    @Cognome = ?,
    @Nome = ?,
    @NomeCompleto = ?,
    @CF = ?

    SELECT @IDUtente as IDUtente", [$cognome, $nome, $nome_completo, $cf]);
Mintendo
  • 557
  • 1
  • 8
  • 24