Reputation: 53
I want to execute an existing stored procedure in SQL Server and get the results out in JSON.
Details: existing stored procedure dbo.pr_GetUser
returns a recordset.
I want to create a wrapper that will do the following:
EXEC dbo.pr_GetUser
FOR JSON AUTO
This will allow me to consume an existing stored procedure and not be concerned about the inner workings or modifications in logic.
Is this possible without editing the existing stored procedure?
Upvotes: 1
Views: 863
Reputation: 409
You can do it like this,
INSERT INTO #table(userId int)
EXEC dbo.pr_GetUser
select userId from #table FOR JSON Auto
Note that table structure of #table will be same as the result.
Upvotes: 2