0

我了解到我可以使用以下内容搜索多个字段:

DECLARE @srch nvarchar(40) 
    SET @srch = '%something%'

SELECT * FROM DataTable dt
    WHERE CONCAT(dt.field1, dt.field2) LIKE @srch

但是,除了使用多个 OR 之外,还有其他方法可以搜索多个条件吗?

DECLARE @srch1 nvarchar(40), @srch2 nvarchar(40), @srch3 nvarchar(40),  
    SET @srch1 = '%this%'
    SET @srch2 = '%that%'
    SET @srch3 = '%the other%'

SELECT * FROM DataTable dt
    WHERE  CONCAT(dt.field1, dt.field2) LIKE @srch1 
        OR CONCAT(dt.field1, dt.field2) LIKE @srch2 
        OR CONCAT(dt.field1, dt.field2) LIKE @srch3

谢谢!

4

1 回答 1

1

这个怎么样?

DECLARE @srch TABLE (srch_field nvarchar(40))

INSERT INTO @srch VALUES ( '%this%'), ('%that%') ,('%the other%')

SELECT * FROM DataTable dt
WHERE  EXISTS (
  SELECT NULL FROM @srch s WHERE CONCAT(dt.field1, dt.field2) LIKE srch_field
)
于 2013-07-03T15:50:21.180 回答