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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在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; 
答案

似乎你必须围绕连接元素()

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)
   ...........
另一答案

在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子句。

另一答案

MS Access需要围绕JOINs的括号:

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; 

以上是关于在sql代码中使用Like运算符。语法错误的主要内容,如果未能解决你的问题,请参考以下文章

SQL like 语句问题

SQL学习——LIKE运算符

使用带参数的 LIKE 时 SQL 引发语法错误 [重复]

请问SQL中的like子句中可以使用的通配符有

在下面的代码片段中的剩余 ='passthrough' 处的代码中出现语法错误

查询包含多个 JOIN 时访问 SQL 语法错误(缺少运算符)