I need to return values from a stored procedure using SQL Server 2000 to a VB6 program. The stored procedure will calculate the values but I can't get it to return the values to the program. Thanks in advance for any help given.
I frequently use a stored procedure to return a value which is then assigned to a variable in VB. The sp needs to use the OUTPUT param and assign a value and the VB proc needs to use ADODB. Here is a sample that will fill the variable lngHolidays with 8 and return 252 for the number of work days in 2005 using the GetWorkDays(#1/1/2005#, #12/31/2005#).
ALTER PROCEDURE spGetHolidayCount
(
@Start datetime,
@End datetime,
@HolidayCount int OUTPUT
)
AS
SELECT @HolidayCount=Count(*)
FROM tblHolidays
WHERE HolidayDate BETWEEN @Start AND @End
RETURN
Public Function GetWorkDays(StartDate As Date, EndDate As Date) As Double
' This function calculates the number of workdays between StartDate and EndDate
' The work week is defined as Monday through Friday.
' The function does not exclude holidays.
Dim pcnnDb As New ADODB.Connection
Dim oCmd As ADODB.Command
Dim oParm1 As ADODB.Parameter
Dim oParm2 As ADODB.Parameter
Dim oParm3 As ADODB.Parameter
Dim lngHolidays As Long
Dim lngWorkDays As Long
Dim dtDate As Date, lngWorkDays As Long
On Error GoTo HandleErr
For dtDate = StartDate To EndDate
If (Weekday(dtDate, 1) <> 1) And (Weekday(dtDate, 1) <> 7) Then
lngWorkDays = lngWorkDays + 1
End If
Next dtDate
Set oCmd = New ADODB.Command
Set oParm1 = New ADODB.Parameter
Set oParm2 = New ADODB.Parameter
Set oParm3 = New ADODB.Parameter
If pcnnDb Is Nothing Or Len(pcnnDb.ConnectionString) = 0 Then
Set pcnnDb = CurrentProject.Connection
End If
HandleErr:
Select Case Err.Number
Case Else
Call ErrorLog("basSchedule_GetWorkDays", Err) 'ErrorHandler:$$N=Form_frmLruMain.cmdLoad_Click
End Select
Resume Exit_Proc
Resume
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.