首页 新闻 会员 周边

多字段模糊查询

0
[已关闭问题]

对数据库中的多个字段进行模糊查询,怎么写sql语句或者存储过程,其中的字段可以为null   拜托!

shuangyu的主页 shuangyu | 初学一级 | 园豆:192
提问于:2009-03-04 08:41
< >
分享
其他回答(2)
0

select * from xxx

where (c1 is null or c1 like '%...%')

    and (c2 is null or c2 like '%...%')

    and...

难道不是这样吗……

Gray Zhang | 园豆:17610 (专家六级) | 2009-03-04 19:31
0

SQLServer全文检索

Assion Yang | 园豆:232 (菜鸟二级) | 2009-03-11 18:05
0

现在想要查找出emailaaa开头的,addressbei开头的记录

 

那么一般我们会构建如下SQL

select * from orders o where o.email like 'aaa%'and o.address like 'bei%'

 

其实我们可以使用如下SQL来缩短SQL语句(也就是连接字段一起进行like操作)

SELECT * FROM orders o where concat(o.email,o.address) like 'like%df%'

 

hzs | 园豆:320 (菜鸟二级) | 2009-03-12 17:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册