2015-09-19 185 views
-2

我調用存儲過程與ADP Access 2003中日期時間類型的參數存儲過程日期時間參數,我得到一個錯誤的結構執行MS SQL服務器從Access 2003

附近有語法錯誤 - '

我試過不同的日期格式,但是錯誤與其他結構重複相同的類型。

Exec的從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 
+0

你能告訴我們什麼價值'.RecordSource'看起來像所有的串連後? –

+0

'.RecordSource'的值是未知的,因爲錯誤'語法錯誤'我得到之前分配。 – anatol

回答

0

古斯塔夫感謝,我找到解決方法。它只需要設置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) = '' 

和報價

0

最有可能你錯過了引號包裹在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") & "#" 
+0

我之前完成了這個 – anatol

+0

然後強制所示的格式,因爲'2015-09-22' _as is_將不起作用,因爲T-SQL中的日期表達式必須用單引號括起來。 – Gustav

+0

謝謝,但它不起作用 – anatol