求救!!!一个模糊查询的问题

爱你99 2006-08-29 10:24:07
现在a表中有字段id,company_name,company_sh等,
我用下面的这条查询语句查不出来company_sh为空的记录,请大侠们指点,谢了!!!
select * from a where company_sh like '%%'

...全文
173 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
freeliu 2006-08-29
  • 打赏
  • 举报
回复
这样试试:
select * from a where company_sh like '''%'+@x+'%'''
爱你99 2006-08-29
  • 打赏
  • 举报
回复

id,company_name,company_sh
1 aaa 111
2 ddd
3 www 555
4 qqq
5 eee 666
各位老大,我是想下面的语句如果@a=''的话,就要把所有的记录包含company_sh都能查出来,如果@a等于其他的话就不能把company_sh为空的记录查出来
select * from a where company_sh like '%'+@x+'%'
如果我输入@x=1,那么理想的结果就是
id,company_name,company_sh
1 aaa 111
如果我输入@x='',那么理想的结果就是
id,company_name,company_sh
1 aaa 111
2 ddd
3 www 555
4 qqq
5 eee 666
怎么实现这样的效果?
csdnweii 2006-08-29
  • 打赏
  • 举报
回复
加上 and 啊
Robin_ftsafe 2006-08-29
  • 打赏
  • 举报
回复
select * from a where isnull(company_sh,'')<>''
爱你99 2006-08-29
  • 打赏
  • 举报
回复
我是想要查出来同时包含不为空的记录
freeliu 2006-08-29
  • 打赏
  • 举报
回复
select * from a where company_sh is null
如果连空串都查出来,那么
select * from a where isnull(company_sh, '') = ''
csdnweii 2006-08-29
  • 打赏
  • 举报
回复
select * from a where company_sh is null
爱你99 2006-08-29
  • 打赏
  • 举报
回复
解决了,在别的地方问到的
select * from A where isnull(company_sh,'''') like :a and isnull(name,'''') like :b order by id

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧