我在SQL Server 2016中有一个名为usp_createRecord
的存储过程,它包含2个参数start_date
和end_date
。
我在MS Access中有一个名为MyReport
的表,其中有8列,其中2列为startDate
和endDate
。
我需要将MS Access中的日期值作为参数传递给SQL Server的存储过程。执行存储过程并将其显示在MS Access中 工作簿。
希望我很清楚。
答案 0 :(得分:0)
我认为您需要一个调用VBA函数的字段的查询,该函数传递您的参数,这些参数返回传递查询中的值,SQL
在运行时确定。
如果你为大量的行调用这样的函数,它会很慢。
例如,您需要与SQL Server的连接进行传递查询。我会称之为qry_PT_createRecord
。
然后,您需要在VBA中使用public function
并传递两个date
参数,这些参数会修改传递查询的sql
属性,例如:
Public Function g_createRecord(startDate As Date, endDate As Date) As Integer
Dim db As Database
Dim qdef As QueryDef
Dim sql As String
Set db = CurrentDb()
Set qdef = db.QueryDef("qry_PT_createRecord")
qdef.sql = "exec usp_createRecord " & startDate & "," & endDate
g_createRecord = qdef.Execute
End Function
然后,您需要一个查询来显示MyReport
中的字段,调用该函数,并返回sp的值(如果有的话)。我将调用该查询qry_createRecord
。 SQL将如下所示:
Select
ID,
startDate,
endDate,
g_createRecord(startdate,enddate)
from
myReport