Question : In a SQL Server 2008 Express stored procedure can you return a rowset and an output parameter?

The following VBA code that calls the stored procedure EMailProspectiveResidentInformation (also shown below).  The rowset is returned successfully but .Parameters("@Error") is NULL which causes an error in its assignment to strError.  Why does this happen?  If I execute this stored procedure in SQL Server Management Studio it works correctly.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
With g_adoCmd
        .CommandText = "EMailProspectiveResidentInformation"
        .CommandType = adCmdStoredProc
        .Parameters.Refresh
        .Parameters("@lID") = Me!pkID ' input value
        Set rs = .Execute    'retrieve the recordset
        strError = .Parameters("@Error")
    End With
 
 
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[EMailProspectiveResidentInformation](
	@lID INT,
	@Error varchar(128) Output )
AS
BEGIN
 
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
   SET NOCOUNT ON;
   Set @Error = ''
   if ( Select COUNT(*) from tblProspectiveResidents where CallID = @lID) = 0
       Begin
	   SET @Error = 'Invalid CallID for tblStates in EMailProspectiveResidentInformation'
       End
   Else 
       Begin   
	   SELECT AT.Description as ApartmentType
	   , FL.Description as FloorLevel
	   , TL.Description as Location
	   , PP.DateNeeded
	   , PP.NumberOfOccupants
	   , PT.Description as PetType
	   , PP.PetWeight
	   , PP.PriceRange
	   , PP.ReasonForMoving
	   , PP.Employer 
	   , PP.EmployerPhoneNumber
	   , TS.TrafficSourceName
	   , PP.LeadType
	   , PP.Appointment
	   , PP.Other
	 
	   FROM tblProspectiveResidents PP
	   INNER JOIN tblApartmentType AT ON PP.ApartmentTypeID = AT.pkID
	   INNER JOIN tblFloorLevel FL ON PP.FloorLevelID = FL.pkID
	   INNER JOIN tblLocation TL ON PP.LocationID = TL.pkID
	   INNER JOIN tblPetType PT ON PP.PetTypeID = PT.pkID
	   INNER JOIN tblTrafficSources TS ON PP.TrafficSourceID = TS.pkID
	 
	   WHERE PP.CallID = @lID
	   End	
 
END
Open in New Window Select All

Answer : In a SQL Server 2008 Express stored procedure can you return a rowset and an output parameter?

You have to specify it as an output parameter.  I believe if you add this prior to line 4 in the above code snippet you will be fine.

.Direction = adParmInputOutput
Random Solutions  
 
programming4us programming4us