处理从MSAccess到SQL Server的日期

时间:2017-02-16 10:16:10

标签: sql-server sql-server-2012 access-vba ms-access-2010

我在SQL Server中有一个存储过程,它会更新几个字段。

ALTER PROCEDURE [HORIZON].[UpdateQuoteRec]
-- Add the parameters for the stored procedure here
@ID bigint
,@IDQuoteStatus bigint
,@IDQuoteSubStatus bigint
,@dtmNextActionDate date
,@dtmClosedDate date
,@IDRepresentativeName bigint
,@perOffered money
,@curAnnualPremiumOffered money
,@IDCompetitorName bigint
,@IDLapseOutcome bigint
,@boolIsHolding bit
,@IDGoneToCompetitor bigint 

AS
BEGIN
SET NOCOUNT ON;
UPDATE HORIZON.tblQuoteCalculationDetails
SET
IDQuoteStatus                   =   @IDQuoteStatus
,IDQuoteSubStatus               =   @IDQuoteSubStatus
,dtmNextActionDate              =   @dtmNextActionDate
,dtmClosedDate                  =   @dtmClosedDate
,IDRepresentativeName           =   @IDRepresentativeName
,perOffered                     =   @perOffered
,curAnnualPremiumOffered        =   @curAnnualPremiumOffered
,IDCompetitorName               =   @IDCompetitorName
,IDLapseOutcome                 =   @IDLapseOutcome
,boolIsHolding                  =   @boolIsHolding
,IDGoneToCompetitor             =   @IDGoneToCompetitor

Where ID            = @ID

END

当我从SQL中执行如下所示时,它可以正常工作

EXECUTE [HORIZON].[UpdateQuoteRec]
@ID =   2
,@IDQuoteStatus =   1
,@IDQuoteSubStatus  =   1
,@dtmNextActionDate =   '11-19-2017'
,@dtmClosedDate =   '05-05-2016'
,@IDRepresentativeName  =   1
,@perOffered    =   17
,@curAnnualPremiumOffered   =   244
,@IDCompetitorName  =   2
,@IDLapseOutcome    =   2
,@boolIsHolding =   0
,@IDGoneToCompetitor    =   1

但是当我通过下面的函数传递它时,我得到以下错误。

This is the error i get

Public Sub cmdUpdateRecord()
If Not (isConnectionOpen()) Then
OpenConnection
End If
Set ADOCom = New ADODB.Command
ADOCom.ActiveConnection = ADOConn
ADOCom.CommandType = adCmdStoredProc
ADOCom.CommandText = "[HORIZON].[UpdateQuoteRec]"
ADOCom.Parameters.Append ADOCom.CreateParameter("@ID", adBigInt, adParamInput, 10, ID)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDQuoteStatus", adBigInt, adParamInput, 10, IDQuoteStatus)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDQuoteSubStatus", adBigInt, adParamInput, 10, IDQuoteSubStatus)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDRepresentativeName", adBigInt, adParamInput, 10, IDRepresentativeName)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDCompetitorName", adBigInt, adParamInput, 10, IDCompetitorName)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDLapseOutcome", adBigInt, adParamInput, 10, IDLapseOutcome)
ADOCom.Parameters.Append ADOCom.CreateParameter("@IDGoneToCompetitor", adBigInt, adParamInput, 10, IDGoneToCompetitor)
ADOCom.Parameters.Append ADOCom.CreateParameter("@boolIsHolding", adBoolean, adParamInput, 5, boolIsHolding)
ADOCom.Parameters.Append ADOCom.CreateParameter("@dtmNextActionDate", adDate, adParamInput, 10, sqlDate(dtmNextActionDate))
ADOCom.Parameters.Append ADOCom.CreateParameter("@dtmClosedDate", adDate, adParamInput, 10, sqlDate(dtmClosedDate))
ADOCom.Parameters.Append ADOCom.CreateParameter("@perOffered", adDouble, adParamInput, 10, perOffered)
ADOCom.Parameters.Append ADOCom.CreateParameter("@curAnnualPremiumOffered", adDouble, adParamInput, 10, curAnnualPremiumOffered)
ADOCom.Execute
End Sub

我已使用函数将日期转换为字符串,如下所示

Public Function sqlDate(IN_Date As Date) As String
Dim DateString As String
DateString = Right("00" + Trim(Str(Month(IN_Date))), 2) & "-" & Right("00" + Trim(Str(Day(IN_Date))), 2) & "-" & Right("0000" + Trim(Str(Year(IN_Date))), 4)
End Function

任何帮助都将受到高度赞赏。处理日期的TBH 一直是我的灰色区域。在某些情况下,我使用了相似的代码并且它有效。: - (

非常感谢

注意:这绝对是我删除SP工作日期的日期。

0 个答案:

没有答案