在SQL代码中使用Like运算符。语法错误

时间:2019-01-29 07:55:09

标签: sql ms-access inner-join sql-like

我想在代码中使用4到5个表。但是在代码之间,我需要使用like运算符来使用contains属性。我已经编写了代码,但是代码给出了语法错误。请告知。

SELECT 
    [RCDT Database].FUNCTIONALITY, 
    [RCDT Database].SPECIFICATION, 
    [RCDT Database].[TEST NAME]
FROM SelectedClearingName 
INNER JOIN Clearing ON (SelectedClearngName.ClearingName=Clearing.ClearingName) 
INNER JOIN FunctionalityWiseClearing ON (Clearing.ClearingName=FunctionalityWiseClearing.Clearing) 
INNER JOIN SelectedValues ON (FunctionalityWiseClearing.Functionality=SelectedValues.ListBoxValues) 
INNER JOIN [RCDT Database] ON ([RCDT Database].FUNCTIONALITY Like "" & [SelectedValued.ListBocValues] & "" 
INNER JOIN SelectedPaytype ON ([RCDT Database].[PAY TYPE]=SelectedPaytype.PaytypeValue; 

3 个答案:

答案 0 :(得分:0)

在Access(已标记)SQL中,它将是:

Like "*" & [Selectedvalues.ListBoxValues] & "*"

编辑:

将其简化为:

SELECT 
    [RCDT Database].FUNCTIONALITY, 
    [RCDT Database].SPECIFICATION, 
    [RCDT Database].[TEST NAME]
FROM 
    [RCDT Database],
    SelectedClearingName 
INNER JOIN 
    Clearing ON (SelectedClearngName.ClearingName=Clearing.ClearingName) 
INNER JOIN 
    SelectedValues ON (FunctionalityWiseClearing.Functionality = SelectedValues.ListBoxValues) 
INNER JOIN 
    FunctionalityWiseClearing ON (Clearing.ClearingName=FunctionalityWiseClearing.Clearing) 
INNER JOIN    
    SelectedPaytype ON ([RCDT Database].[PAY TYPE]=SelectedPaytype.PaytypeValue
WHERE
    [RCDT Database].FUNCTIONALITY Like "*" & [SelectedValued.ListBocValues] & "*" 

这里缺少的是Access SQL令人费解的括号,我从没想过。

因此,删除Where子句,使用GUI设计器创建内部联接,然后添加Where子句。

答案 1 :(得分:0)

似乎您必须在()周围加入很多元素

SELECT 
    [RCDT Database].FUNCTIONALITY, 
    [RCDT Database].SPECIFICATION, 
    [RCDT Database].[TEST NAME]
FROM  SelectedClearingName 
    INNER JOIN Clearing ON (SelectedClearngName.ClearingName=Clearing.ClearingName)
    INNER JOIN FunctionalityWiseClearing ON (Clearing.ClearingName=FunctionalityWiseClearing.Clearing) 
    INNER JOIN SelectedValues ON (FunctionalityWiseClearing.Functionality=SelectedValues.ListBoxValues)
   ...........

答案 2 :(得分:0)

MS Access需要在JOIN前后加上括号:

SELECT [RCDT Database].FUNCTIONALITY, [RCDT Database].SPECIFICATION, [RCDT Database].[TEST NAME]
FROM ((((SelectedClearingName INNER JOIN
         Clearing
         ON SelectedClearngName.ClearingName = Clearing.ClearingName
        ) INNER JOIN
        FunctionalityWiseClearing
        ON Clearing.ClearingName = FunctionalityWiseClearing.Clearing
       ) INNER JOIN
       SelectedValues
       ON FunctionalityWiseClearing.Functionality = SelectedValues.ListBoxValues
      ) INNER JOIN
      [RCDT Database]
      ON [RCDT Database].FUNCTIONALITY Like "" & [SelectedValued.ListBocValues] & "" 
     ) INNER JOIN
     SelectedPaytype
     ON ([RCDT Database].[PAY TYPE] = SelectedPaytype.PaytypeValue;