比如我要写select * from a where id<>''或者select * from a where isnull(id,'')<>'',其中在id上建有索引,但是以上两种情况索引无效,请问有什么办法可以让索引有效果呢?? 

解决方案 »

  1.   

    select * from a where LEN(id)>0
      

  2.   

    测试:select * from a where id is not null
      

  3.   

    select * from a (index='索引名') where id<>''
    有种情况就是用索引比不用索引慢
      

  4.   

    也不行,而且null和空值还是有区别的
      

  5.   

    SELECT TOP 1000 [LogId]
          ,[PostTime]
      FROM [Test].[dbo].[tblDdlLog] where LogId<>'' 我怎么测试用了索引呢。
      

  6.   

    说白了 没办法 用isnull(col,'')<>'' ,用不到索引
      

  7.   

    直接写<>''也可以 null<>''
      

  8.   


    id is not null or id <> ''
      

  9.   

    index hintselect * from a with(index(ix_xxx)) where id<>''
      

  10.   


    select * from a alias
    where not exists
         ( select * from a where id = '' and alias.pk = pk)
      

  11.   

    perfect!!!非常感谢,马上给分