Results 1 to 5 of 5
  1. #1
    WAstarita is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    consult-wa.com
    Posts
    5

    Pass Through Query using a Stored Procedure with an Output Variable

    I know there are probably 20 different ways of doing this but I'm new at pass through queries so I want to learn the proper syntax. I have a stored procedure that counts the amount of e-mail addresses on file for a particular employee. Basically a fast version of DCount("ID", "EMAILS", "EMPLOYEEID = " & ID).

    Code:
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    
    ALTER PROCEDURE [dbo].[EmployeeEmailCount]
    	@EMPID as bigInt, @EMPCount as Int Output
    AS
    BEGIN
    	SET NOCOUNT ON;
    	SELECT @EMPCount = Count(*) From EmployeeContactEmails where EmployeeID = @EMPID
    END
    I created as simple pass through query:


    Code:
    exec "employeeemailcount" @EMPID = 6
    This should return 2 but I get an error:

    Code:
    Procedure of Function 'EmployeeEmailCount' expects parameter '@EMPCount', which was not supplied"
    If I just add @EMPCount to the end of the query it tells me I have to declare the scalar value @EMPCount. How should the syntax read for the output variable?

    Thanks in advance

  2. #2
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    In pass through queries, treat them as if they were being run directly from your SQL Server window... so in this case:

    exec employeeemailcount @EMPID = 6

    (No quotes...)

    See if that works...

  3. #3
    WAstarita is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    consult-wa.com
    Posts
    5
    I tried that, its still expecting the output variable.

  4. #4
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    What happens if you run the proc from the sql command line? Do you need a '6' at @EMPID='6'?

  5. #5
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    Just realized something - if you are attempting to pass the data dynamically from access, you can't actually do that in the SQL query dynamically. You would need to dynamically create a static SQL call each time and pass that through to the server.

    check here for more info:
    http://www.pcreview.co.uk/forums/exe...-t1895461.html

Please reply to this thread with any new information or opinions.

Similar Threads

  1. write stored procedure with 'if else'
    By shital in forum Access
    Replies: 9
    Last Post: 04-11-2018, 11:47 AM
  2. VBA Pass-through Query with Variable
    By smaumau in forum Programming
    Replies: 0
    Last Post: 12-06-2010, 09:10 AM
  3. Pass image parameter to stored procedure
    By Kencao in forum Programming
    Replies: 3
    Last Post: 04-28-2010, 11:51 PM
  4. Passing variable values to Stored Procedure
    By rodrigopcnet in forum Access
    Replies: 1
    Last Post: 04-14-2010, 10:35 AM
  5. Replies: 1
    Last Post: 04-13-2010, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums