在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需要围绕JOIN
s的括号:
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运算符。语法错误的主要内容,如果未能解决你的问题,请参考以下文章