[英]Problem using where with date in SQL Statement
我試圖在VBA腳本中執行SQL語句。 我已經讓腳本運行了,但它忽略了日期過濾器的位置。
我已經研究並嘗試了我能找到的每一個選項,但似乎無法讓它發揮作用。
Set rs = conn.Execute("Select [adjustment_number], [status], [tax_adjusted],[amount], [gl_date],[creation_date],[apply_date],[comments],[type],[adjustment_type],[dbo].[Code_Combinations].[segment1], [dbo].[Code_Combinations].[segment10],[dbo].[Code_Combinations].[segment11],[dbo].[Code_Combinations].[segment12],[dbo].[Code_Combinations].[code_combination] FROM [dbo].[AR_ADJUSTMENTS_ALL] " & _
"left outer join [dbo].[Code_Combinations] on [dbo].[AR_ADJUSTMENTS_ALL].[CODE_COMBINATION_ID] = [dbo].[Code_Combinations].[CODE_COMBINATION_ID] where [gl_date] >= " & gldate & ";")
(將我的評論從上面的評論復制到答案中,因為這解決了你的問題)
SQL Server? 在WHERE
子句中將單引號括在日期周圍。
where [gl_date] >= '" & gldate & "';"
假設gldate
是有效日期, [gl_date]
是日期數據類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.