0

我想使用 1 个变量搜索一张表和多列。我的代码如下所示:

SELECT        lCustomerID, sLastName, sFirstName, sAddress1, sAddress2, 
  sCity, sState, sZipcode , @search AS Expr1
FROM            Customers
WHERE (sLastName = N'Includes @search') 
OR    (sFirstName = N'includes @search') 
AND   (sBarcode = N'includes @search')

我希望它包含字符串 not =

4

1 回答 1

0

假设您打算拥有所有 OR,并且“我希望它包含字符串”意味着您想要部分匹配(例如,搜索“John”会产生“Johnson”和“RoJohn”),那么您正在寻找 LIKE 关键字:

WHERE sLastName  LIKE N'%' + @search + '%'
   OR sFirstName LIKE N'%' + @search + '%'
   OR sBarCode   LIKE N'%' + @search + '%';
于 2012-06-13T03:47:04.873 回答