有如下表:
table1id ry rq(字符型)
1 AB 2006-3-1
2 AC 2006-4-2
3 AD 2006
4 CD 修理由于rq字段是 字符型的,所以我想屏蔽非标准日期型的记录,再做查询.....该怎么写SQL啊?
table1id ry rq(字符型)
1 AB 2006-3-1
2 AC 2006-4-2
3 AD 2006
4 CD 修理由于rq字段是 字符型的,所以我想屏蔽非标准日期型的记录,再做查询.....该怎么写SQL啊?
insert into test(id,ry,rq)
select 1,'AB','2006-3-1' union all
select 2,'AC','2006-4-2' union all
select 3,'AD','2006' union all
select 4,'CD','修理'select * from test where isdate(rq) > 0drop table test
lz的意思用这句是不是更满足要求
select * from test where len(convert(char(8),rq,112))=8
如果写成这样:
select * from table1 where isdate(rq) > 0 and cast(rq,as datetime)>'2006-4-1'运行后报错啊!
insert into test(id,ry,rq)
select 1,'AB','2006-3-1' union all
select 2,'AC','2006-4-2' union all
select 3,'AD','2006' union all
select 4,'CD','修理'
select * from test
where len(convert(char(8),rq,112))=8 and convert(char(8),rq,112)>'0-0-0'drop table test