I am working on project which is on Laravel and Sql Server. In database, we have a store procedure that takes two arguments (Both arguments are integer) and return a integer value. Below is the query that I run on sql server and perfectly gives result:
DECLARE @return_value int, @RetMsg nvarchar(50);
EXEC @return_value = [dbo].[GetStudentStatus]
@StudentID = 1234,
@Results = 1,
@RetMsg = @RetMsg OUTPUT;
SELECT @return_value As status;
Above execution, gives me result in column named as "status".
Now, I want to execute this store procedure from Laravel where I will pass studentID and Results status and get status of student. But I have no idea how can I achieve this.
I have tried following ways to achieve the same:
Logic 1:
\DB::statement(\DB::raw('DECLARE @return_value int, @RetMsg nvarchar(50)'));
\DB::statement(\DB::raw('@return_value = EXEC dbo.GetStudentStatus @StudentID = ?, @Results = ?, @RetMsg = @RetMsg OUTPUT'), [1234, 1]);
$status = \DB::selectOne('SELECT @return_value As status', []);
Logic 2:
$status = \DB::selectOne('DECLARE @return_value int, @RetMsg nvarchar(50); @return_value = EXEC dbo.GetStudentStatus @StudentID = ?, @Results = ?, @RetMsg = @RetMsg OUTPUT; SELECT @return_value As status', [1234, 1]);
Logic 3:
\DB::statement(\DB::raw('DECLARE @return_value int, @RetMsg nvarchar(50) @return_value = EXEC dbo.GetStudentStatus @StudentID = ?, @Results = ?, @RetMsg = @RetMsg OUTPUT'), [1234, 1]);
$status = \DB::selectOne('SELECT @return_value As status', []);
Unfortunately, no logic is working for me. Can someone please help me on this? How can I get student status by passing student id and result status to this store procedure?
Thanks in Advance
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire