Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Stored Procedure with Output parameters of type varchar and returncode #866

Closed
Trobeloo opened this issue Sep 5, 2021 · 2 comments
Labels
question Further information is requested

Comments

@Trobeloo
Copy link

Trobeloo commented Sep 5, 2021

I have a stored procedure with an output parameter and a return value:
ALTER PROCEDURE [dbo].[TESTSP] (@gmnv nvarchar(20) OUTPUT)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT @gmnv = 'String100';
Return 123456;

END

I want to retrieve both the output value and the return value. As I can see there is a bug with Output parameters of type varchar #836.

Before that bug is fixed is there an alternative way to do that?

@Trobeloo Trobeloo added the question Further information is requested label Sep 5, 2021
@Trobeloo Trobeloo changed the title Question: <What is your question?> Question: Store Procedure with Output parameters of type varchar and returncode Sep 5, 2021
@Trobeloo Trobeloo changed the title Question: Store Procedure with Output parameters of type varchar and returncode Question: Stored Procedure with Output parameters of type varchar and returncode Sep 5, 2021
@mikependon
Copy link
Owner

Your case is returning 2 values and the answer to that is yes, you can hack it via explicit execution approach like below.

var sql = @"DECLARE @gmnv NVARCHAR(20);
     EXEC sp_Test @gmnv OUTPUT;
     SELECT @gmnv;";
using var extractor = connection.ExecuteQueryMultiple(sql);
var returnValue = extractor.Scalar<int>();
var gmnv = extractor.Scalar<string>();

The code is not tested but we did it this way in the past. Hope this helps! 😄

@Trobeloo
Copy link
Author

Trobeloo commented Sep 6, 2021

I was not able to use your suggestion but no problem as I cloned and compiled the master branch. It is now working with a DirectionalQueryField and the size property.

@Trobeloo Trobeloo closed this as completed Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants