SQL 查询错误让我发疯!

Bro*_*ius 0 sql-server

我想知道是否有人可以在我的 SQL-Query 中找到我似乎找不到的错误.. 一直在同一行代码上运行大约 2 个小时,这让我发疯了!

所以,这是查询...(很长,但希望它是可读的...)我在 VBA 中工作,连接到数据库,因此 ComboBox 值和变量。

我得到的错误说

RfD_ 附近的语法不正确

所以,它来了。振作起来:

SQLString = 
"SELECT 
RfD_.RfD_ID
, RfD_.RfD_Version
, RfD_Status
, RfD_ProjectRef
, RfD_ProjectName
, RfD_StartDate
, RfD_FinishedDate, " & _

"RfD_ActivityName
, Deliverables_.Deliverables_ID
, Deliverables_.Deliverables_Deliverable
, Deliverables_.Deliverables_AcceptanceCriteria
, Deliverables_.Deliverables_Deadline
, Deliverables_.Deliverables_Delivered 
FROM [RFD_New].[dbo].[RfD_] " & _

"Inner join [RFD_New].[dbo].[Deliverables_] 
    on RfD_.RfD_ID = Deliverables_.RfD_ID" & _
    "And RfD_.RfD_Version = Deliverables_.RfD_Version 
where RfD_.RfD_StartDate >= '" & DateFrom & "' 
    and RfD_.RfD_FinishedDate <= '" & DateTo & "' " & _

    "And RfD_.RfD_ID in (
                        SELECT RfD_ID 
                        From [RFD_New].[dbo].[Approval_] 
                        Where Approval_ID = '" & 1 & "' 
                            And (Approval_Name = '" & ComboBox2.value & "' 
                            or Approval_Name = '" & TwistName(ComboBox2.value) & "') " & _

    "And RfD_.RfD_ID in (
                        SELECT RfD_ID 
                        From [RFD_New].[dbo].[RfD_] 
                        Where RfD_ProjectRef = '" & ComboBox1.value & "') "
Run Code Online (Sandbox Code Playgroud)

对其进行了一些格式化以使其更具可读性,但没有改变任何内容。有趣的是它在 Microsoft SQL Server Management Studio 中有效,但在 VBA 中无效。

小智 6

如果这是您的确切代码,则您忘记在此行的末尾放置一个空格:

FROM [RFD_New].[dbo].[RfD_]" & _
Run Code Online (Sandbox Code Playgroud)