求除去空值,但是不能用索引,怎么办呢

wzszy 2010-10-15 09:06:40
比如我要写select * from a where id<>''或者select * from a where isnull(id,'')<>'',其中在id上建有索引,但是以上两种情况索引无效,请问有什么办法可以让索引有效果呢??
...全文
160 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzszy 2010-10-15
  • 打赏
  • 举报
回复
同时也谢谢楼上几位热心帮忙!!
wzszy 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 cjzm83 的回复:]
SQL code

select * from a alias
where not exists
( select * from a where id = '' and alias.pk = pk)
[/Quote]perfect!!!非常感谢,马上给分
cjzm83 2010-10-15
  • 打赏
  • 举报
回复

select * from a alias
where not exists
( select * from a where id = '' and alias.pk = pk)
wzszy 2010-10-15
  • 打赏
  • 举报
回复
还有没有办法呢??各位大侠
wzszy 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 cjzm83 的回复:]
index hint

SQL code

select * from a with(index(ix_xxx)) where id<>''
[/Quote]用时7秒,更慢了
cjzm83 2010-10-15
  • 打赏
  • 举报
回复
index hint

select * from a with(index(ix_xxx)) where id<>''
dawugui 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 wzszy 的回复:]
比如我要写select * from a where id<>''或者select * from a where isnull(id,'')<>'',其中在id上建有索引,但是以上两种情况索引无效,请问有什么办法可以让索引有效果呢??
[/Quote]

id is not null or id <> ''
bancxc 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bancxc 的回复:]

说白了 没办法

用isnull(col,'')<>'' ,用不到索引
[/Quote]直接写<>''也可以 null<>''
bancxc 2010-10-15
  • 打赏
  • 举报
回复
说白了 没办法

用isnull(col,'')<>'' ,用不到索引
wzszy 2010-10-15
  • 打赏
  • 举报
回复
没有也,又是小小菜同学,真谢谢你了
王向飞 2010-10-15
  • 打赏
  • 举报
回复
SELECT TOP 1000 [LogId]
,[PostTime]
FROM [Test].[dbo].[tblDdlLog] where LogId<>''
我怎么测试用了索引呢。。。。
wzszy 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 just4 的回复:]
测试:select * from a where id is not null
[/Quote]也不行,而且null和空值还是有区别的
rucypli 2010-10-15
  • 打赏
  • 举报
回复
select * from a (index='索引名') where id<>''
有种情况就是用索引比不用索引慢
wzszy 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zsh0809 的回复:]
select * from a where LEN(id)>0
[/Quote]也没用哦,用执行计划查看了下,不过谢谢楼上的回复,书上有句话是有函数的索引就不能用,我想这里卧虎藏龙,肯定有人有办法的
就是just4 2010-10-15
  • 打赏
  • 举报
回复
测试:select * from a where id is not null
「已注销」 2010-10-15
  • 打赏
  • 举报
回复
select * from a where LEN(id)>0

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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