Last active
March 10, 2019 12:18
-
-
Save ezhov-da/01a3a67ece58aab7970d46ab7585cab7 to your computer and use it in GitHub Desktop.
vba получение значения из процедуры
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create PROCEDURE CheckExpedite | |
@InputX varchar(10), | |
@InputY int, | |
@HasExpedite int out | |
AS | |
BEGIN | |
Select @HasExpedite = 9 from <Table> | |
where Column2 = @InputX and Column3 = @InputY | |
If @HasExpedite = 9 | |
Return 2 | |
Else | |
Return 3 | |
End | |
Sub CheckValue() | |
Dim InputX As String: InputX = "6000" | |
Dim InputY As Integer: InputY = 2014 | |
'open connnection | |
Dim ACon As New Connection | |
'ACon.Open ("Provider=SQLOLEDB;Data Source=<SqlServer>;" & _ | |
' "Initial Catalog=<Table>;Integrated Security=SSPI") | |
'set command | |
Dim ACmd As New Command | |
Set ACmd.ActiveConnection = ACon | |
ACmd.CommandText = "CheckExpedite" | |
ACmd.CommandType = adCmdStoredProc | |
'Return value must be first parameter else you'll get error from too many parameters | |
'Procedure or function "Name" has too many arguments specified. | |
ACmd.Parameters.Append ACmd.CreateParameter("ReturnValue", adInteger, adParamReturnValue) | |
ACmd.Parameters.Append ACmd.CreateParameter("InputX", adVarChar, adParamInput, 10, InputX) | |
ACmd.Parameters.Append ACmd.CreateParameter("InputY", adInteger, adParamInput, 6, InputY) | |
ACmd.Parameters.Append ACmd.CreateParameter("HasExpedite", adInteger, adParamOutput) | |
Dim RS As Recordset | |
Dim RecordsAffected As Long | |
'execute query that returns value | |
Call ACmd.Execute(RecordsAffected:=RecordsAffected, Options:=adExecuteNoRecords) | |
'execute query that returns recordset | |
'Set RS = ACmd.Execute(RecordsAffected:=RecordsAffected) | |
'get records affected, return value and output parameter | |
Debug.Print "Records affected: " & RecordsAffected | |
Debug.Print "Return value: " & ACmd.Parameters("ReturnValue") | |
Debug.Print "Output param: " & ACmd.Parameters("HasExpedite") | |
'use record set here | |
'... | |
'close | |
If Not RS Is Nothing Then RS.Close | |
ACon.Close | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment