有如下表:
table1id    ry       rq(字符型)
1     AB        2006-3-1
2     AC        2006-4-2
3     AD        2006
4     CD        修理由于rq字段是 字符型的,所以我想屏蔽非标准日期型的记录,再做查询.....该怎么写SQL啊?

解决方案 »

  1.   

    create table test(id int,ry nvarchar(20),rq nvarchar(30))
    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
      

  2.   

    借用楼上的test表
    lz的意思用这句是不是更满足要求
    select * from test where len(convert(char(8),rq,112))=8
      

  3.   

    select * from test where len(convert(char(8),rq,112))=8
      

  4.   

    大家 没明白我的意思,比如说,我要查询:rq大于'2006-4-1' 的数据!该怎么写SQL语句呢?
     
    如果写成这样: 
    select * from table1 where  isdate(rq) > 0 and cast(rq,as datetime)>'2006-4-1'运行后报错啊!
      

  5.   

    create table test(id int,ry nvarchar(20),rq nvarchar(30))
    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