Solved

Pass-Through queries with OUTPUT parameters

Posted on 2013-12-18
4
1,020 Views
Last Modified: 2014-01-27
Hi,
I would like to read an output parameter from a SQL stored procedure that I am calling from an MS Access Linked Front End via a pass-through query.

I am opening up an ado recordset using the pass-through which returns the records if criteria is met, however when criteria is not met, I am setting a 'Return_Cde' and 'Return_Msg' output params to messages used by the FE. I am not able to figure out how to reference the output parameter defined in the sp.

Pass-Through Returns Records property set to true.

Thanks.
0
Comment
Question by:Howiee22
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 39728189
Here is an example: See if you can adopt in your scenario.
scalar function, checks a parameter value and returns a value.
if object_id(N'ufn_Scalar',N'FN') is not null
	drop function ufn_Scalar;
go
create function dbo.ufn_Scalar (@parameter_name AS nvarchar(25))
RETURNS nvarchar(25)
with execute as caller
AS
BEGIN
	declare @parameter_out nvarchar(25)
	if @parameter_name='1' 
		set @parameter_out='The value is 1'
	else
		set @parameter_out='The value is not 1'
	RETURN (@parameter_out)
END;

Open in new window


Here is a pass-through query in Access front end: When you run it, asks you for the DSN
SELECT dbo.ufn_Scalar('2');
'Result
'The value is not 1

Open in new window

0
 

Author Comment

by:Howiee22
ID: 39729105
Thanks. I will give this a try. One thing I was able to determine, is if I open an ADO recordset  to the results of the sp, then I am not able to read the output parameter. If I close the recordset, then I can access the value of the parameter as set in the sp. Is there another way to approach this as to being able to read output AND continue using the recordset?
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39730159
If you can help in creating the issue, I might be able to answer.
Try to send the sql to create a table in MSSQL, and a simple Access FE.
0
 

Author Comment

by:Howiee22
ID: 39814023
Hi, sorry for not getting back to this... From what I was able to determine, once you close the recordset object, I am able to access the output/return variables.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question