Sidebar

Can a parameterized query implement output parameters for a stored procedure?

0 votes
601 views
asked Mar 31, 2020 by lewis-s-9714 (1,020 points)

I'm calling a stored procedure on SQL Server that has output parameters. The way we have been handling it is declaring variables in the query and then a select statement like this:

var result = qie.doQuery('ServerExample', "DECLARE @p1 varchar(255); EXEC OutputVarChar @p1 output; SELECT @p1 as N'vchOutput';");

 I prefer to use parameterized queries instead, but I'm not sure how it should work. I tried using "\@p1" to escape the at sign so it isn't interpretted as a parameter but I get the error that it's a bad escapement. Is there a way to get the output parameter to work or is it not compatible?

2 Answers

+1 vote
 
Best answer

As of version .48, support for OUTPUT parameters has been added to QIE. See example in this question:

Using a Stored Procedure with Output Parameters in QIE?

Additional examples can be found in this question:

How to call a stored procedures in QIE?

answered Jul 20, 2021 by rich-c-2789 (17,490 points)
0 votes

Currently, parameters which are set within the context of qie.getParameterizedQuery() are INPUT only parameters.

So, here are the options.  Your existing solution should continue to work, although, as you mentioned, it does not use the parameterized queries.

You do have the option to manually connect and specify your OUTPUT parameters on the statement object.  This KB describes how to manually connect to and call a stored procedure with OUTPUT parameters: https://www.qvera.com/kb/index.php/704/how-to-call-a-stored-procedure-with-output-parameters?show=704#q704

I will also create an enhancement request to allow our qie.getParameterizedQuery() object to handle OUTPUT parameters.

answered Mar 31, 2020 by mike-r-7535 (13,830 points)
...