我了解到,我可以使用以下内容搜索多个字段:
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谢谢!
发布于 2013-07-03 23:50:21
这个怎么样?
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
)https://stackoverflow.com/questions/17451172
复制相似问题