--以下都是在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--请假高手为什么出现这样的情况
--本来是想查询一列,该列为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--请假高手为什么出现这样的情况
不过测试了一下isnumeric函数
select isnumeric('0000d34')返回1select isnumeric('0000c34')返回0
好像有点问题
第一个若是错误的 这整个判断句都是错误的 第二句没必要执行
肯定是有先后顺序的
你的第一种是先挑出数字类型的 再去判断id
第二种是先判断id 这时候你的id中有char型 肯定不可以
go
alter table temp_a add constraint id primary key(id);
go你都把他转换成char型 那两句能运行才怪
而d开头表示double型,e开头科学计数型