简体   繁体   English

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

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

I'm calling a stored procedure with a parameter of a datetime type from ADP Access 2003 and I get an error我正在使用 ADP Access 2003 中的日期时间类型的参数调用存储过程,但出现错误

Incorrect syntax near the structure '-'结构“-”附近的语法不正确

I tried different date formats, but the error is repeated the same type with other structures.我尝试了不同的日期格式,但错误与其他结构的类型相同。

Exec from VBA从 VBA 执行

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

After concatenations it looks串联后看起来

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

Stored procedure存储过程

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 

Most likely you miss the quotes to wrap date/time expressions in T-SQL:您很可能错过了在 T-SQL 中包装日期/时间表达式的引号:

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

using Format for T-SQL:使用 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") & "'"

using Format for Access:使用访问格式:

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

Thanks Gustav, I'm find solution.谢谢古斯塔夫,我找到了解决方案。 It simply was needs to set varchar type of parameter.它只是需要设置 varchar 类型的参数。 Not date or datetime.不是日期或日期时间。

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) = '' 

And quotes和报价

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

相关问题 如何从VBA使用datetime参数调用SQL Server存储过程? - How to call SQL Server stored procedure with datetime parameter from VBA? 从 Crystal Reports 到 SQL Server 存储过程的日期时间参数格式 - Datetime parameter format from Crystal Reports to SQL Server stored procedure 从 MS Access 更新查询在 SQL 服务器中创建存储过程 - Create stored procedure in SQL Server from a MS Access update query MS Access调用SQL Server存储过程 - MS Access call SQL Server stored procedure 将参数从访问变量传递到SQL Server存储过程 - Pass Parameter(s) from Access Variable to SQL Server Stored Procedure MS SQL Server中访问与存储过程中的存储查询 - Stored Queries in access vs. Stored Procedure in MS SQL Server 从MS SQL SERVER和MS ACCESS调用存储过程的结果之间的差异 - Difference between results of calls stored procedure from MS SQL SERVER and MS ACCESS MS SQL SERVER 2005 + SQLAlchemy +存储过程+输出参数 - MS SQL SERVER 2005 + SQLAlchemy + Stored Procedure + output parameter SQL Server存储过程中的datetime参数选择数据 - SQL Server stored procedure datetime parameter on selecting data 尝试在MS SQL Server上运行存储过程时访问被拒绝 - Access denied when trying to run stored procedure on MS SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM