繁体   English   中英

使用 Access 2003 中的日期时间参数执行 MS SQL Server 存储过程

[英]Execution MS SQL Server stored procedure with datetime parameter from Access 2003

我正在使用 ADP Access 2003 中的日期时间类型的参数调用存储过程,但出现错误

结构“-”附近的语法不正确

我尝试了不同的日期格式,但错误与其他结构的类型相同。

从 VBA 执行

Me.items.Form.RecordSource = "exec usp_pct_ItemForTree " & cur & "," & usl & ",-1,1,'" & Nz(fltr, "") & "'" & "," & Abs(Nz(inet, 0)) & "," & idb & "," & DueDate

串联后看起来

"exec usp_pct_ItemForTree 0,6,-1,1,'',0,5425157,2015-09-22"

存储过程

alter procedure [dbo].[usp_pct_ItemForTree]
    @group_id int = 21, 
    @instoreonly int = 1,
    @idbrand int = -1,
    @hotim bit = 1,
    @fltr varchar(150) = '',
    @inet bit = 0,
    @idbill int = null,
    @dueDate datetime = null 

您很可能错过了在 T-SQL 中包装日期/时间表达式的引号:

Me.items.Form.RecordSource = "exec usp_pct_ItemForTree " & cur & "," & usl & ",-1,1,'" & Nz(fltr, "") & "'" & "," & Abs(Nz(inet, 0)) & "," & idb & ",'" & DueDate & "'"

使用 T-SQL 格式:

Me.items.Form.RecordSource = "exec usp_pct_ItemForTree " & cur & "," & usl & ",-1,1,'" & Nz(fltr, "") & "'" & "," & Abs(Nz(inet, 0)) & "," & idb & ",'" & Format(DueDate, "yyyy-mm-dd") & "'"

使用访问格式:

Me.items.Form.RecordSource = "exec usp_pct_ItemForTree " & cur & "," & usl & ",-1,1,'" & Nz(fltr, "") & "'" & "," & Abs(Nz(inet, 0)) & "," & idb & ",#" & Format(DueDate, "yyyy-mm-dd") & "#"

谢谢古斯塔夫,我找到了解决方案。 它只是需要设置 varchar 类型的参数。 不是日期或日期时间。

alter procedure [dbo].[usp_pct_ItemForTree]
@group_id int = 21, 
@instoreonly int = 1,
@idbrand int = -1,
@hotim bit = 1,
@fltr varchar(150) = '',
@inet bit = 0,
@idbill int = null,
@dueDate varchar(10) = '' 

和报价

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM