--以下都是在SQL2000查询分析器上写的,可以直接复制上去看
--本来是想查询一列,该列为vachar型
--查出里面为数字的列中,值大于2的记录,没想到搞出这么多烦恼,求助
--比如 '1','2','3','11','b','C'  这些记录中过滤出可以转为数值型的 就是'1','2','3','11' 我要查出>2的,就是 '3','11'--drop table temp_a--------------------建表-------------
if exists (select * from sysobjects where id = object_id(N'temp_a') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table temp_acreate table temp_a (id varchar(10))------------------插入数据-----------
insert into temp_a(id)
values('1')
insert into temp_a(id)
values('2')
insert into temp_a(id)
values('3')
insert into temp_a(id)
values('4')
insert into temp_a(id)
values('a')
insert into temp_a(id)
values('b')
insert into temp_a(id)
values('c')
insert into temp_a(id)
values('D')
--试试这个---------查询代码1-----------------------
select id from temp_a
where  isnumeric(id)=1 and convert(integer,id)>2  
--再试试这个-------查询代码2------这个我可以理解为有先后次序的---
select id from temp_a
where  convert(integer,id)>2  and isnumeric(id)=1-------------------建立主键-------------------------
alter table temp_a alter column id char(10) not null;
go
alter table temp_a add constraint id primary key(id);
go
--建立主键后再试试代码1 代码2-------------------删除主键-------------------------
alter table temp_a drop constraint id
go
--删除主键后在试试代码1 代码2--请假高手为什么出现这样的情况

解决方案 »

  1.   

    在没建立index的情况下,把判断isnumeric放在where的第一个条件,确实可以得到我要的结果,这并不能解决问题啊 - -! 我想知道为什么建立了索引,就没用了,而且建立了索引后,用嵌套查询都查不出来
      

  2.   

    楼主,我用你的代码在sql2005里运行正常。
    不过测试了一下isnumeric函数
    select isnumeric('0000d34')返回1select isnumeric('0000c34')返回0
    好像有点问题
      

  3.   

    and 是先判断第一个  若第一个正确在判断第二个
    第一个若是错误的  这整个判断句都是错误的  第二句没必要执行 
    肯定是有先后顺序的
    你的第一种是先挑出数字类型的 再去判断id
    第二种是先判断id 这时候你的id中有char型 肯定不可以
      

  4.   

    alter table temp_a alter column id char(10) not null; 
    go 
    alter table temp_a add constraint id primary key(id); 
    go你都把他转换成char型 那两句能运行才怪
      

  5.   

    一般isnumeric()参数要求是数据,不可包含字母
    而d开头表示double型,e开头科学计数型