Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ljlizarraga's avatar

How to loop through multiple result sets from stored procedure in Laravel?

Im slightly going out of my mind trying to get 3 result sets from a stored procedure (SP) in SQL server 2012.

EXAMPLE

CREATE PROCEDURE db_abbTest
AS
BEGIN
        SET NOCOUNT ON;

        SELECT 1
        SELECT 2
        SELECT 3
        RETURN 0
END
GO

The SP returns three results (3x select statements) however i cannot seem to get all of the results back from the query. Any Ideas? I have tried while(sqlsrv_fetch_object($r){//do something}) but no luck..

Please help me !!!

here a example real

0 likes
6 replies
jlrdw's avatar

Why are you doing 3 selects at one time.

And have you tried. Net core with razor pages. Just curious.

And you should upgrade SQL Server to a minimum of 2014.

An article with stored procedures I have used as a guide, not laravel, but may help you figure out some things.: https://www.c-sharpcorner.com/article/razor-page-web-application-with-asp-net-core-using-ado-net/

Also I know sql server 2014 has the offset and fetch next n, I don't remember if 2012 had it or not. But it's a real time saver.

ljlizarraga's avatar

Hey good morning. If you take a look at the image, you will see that both results are different from each other yet necessary for the data that I need, and this is how the QUERY functions in the Store Procedure. I need this to run in PHP , NOT net core. Thank you so much.

Please or to participate in this conversation.