例如有一张表,有三个字段a,b,c ,数据像这样
 a        b        c
1965/0001 0001 1965
1965/0002 0002 1965
1965/0005 0005 1965
1965/0007 0007 1965
1965/0009 0009 1965
1965/0010 0010 1965
   .              .         .
   .              .         .
1974/0003 0003 1974
1974/0004 0004 1974
1974/0007 0007 1974
1974/0011 0011 1974怎样用SQL查询1965/0005到1974/007之间的数据?

解决方案 »

  1.   

    select * from @T where cast(REPLACE(a,'/','') as int) 
    between cast(REPLACE('1965/0005','/','') as int) and
    cast(REPLACE('1974/0007','/','') as int)
      

  2.   

    把/用REPLACE然后再比较大小就可以了。像楼上那样。
      

  3.   

    楼上的方法很灵活
    试试这个,没有调试过,提供个思路,希望有点帮助:
    select * from
    (select * from table where  b>0005 and c between 1965 and 1974 )as temp 
    where (case temp.c when 1974 then temp.b<0007)
      

  4.   

    select * from 
    (select * from table where  c between 1965 and 1974 )as temp 
    where (case temp.c when 1965 then temp.b >0005) and (case temp.c when 1974 then temp.b <0007)
      

  5.   

    select * from @T where cast(REPLACE(a,'/','') as int) 
    between cast(REPLACE('1965/0005','/','') as int) and
    cast(REPLACE('1974/0007','/','') as int)
      

  6.   

    其实你可以用sqldatasoure空间实现连接和查询,然后就代码复制出来,这样就没有必要自己编写代码实例:OleDbConnection conn = new OleDbConnection();
                conn.ConnectionString = "provider=SQLOLEDB;data Soure =127.0.0.1;Integrated Security=SSPI;Initial Catalog=degree";
                conn.Open();
                DataSet ds = new DataSet();
                string sql = "SELECT * FROM [chengji] WHERE ([fenshu] >= 400) ORDER BY [fenshu] ASC";
                OleDbDataAdapter dr = new OleDbDataAdapter(sql, conn);
                
                dr.Fill(ds, "dd");
                GridView1.DataSource = ds;
                this.GridView1.DataBind();
                ds.Dispose();
                conn.Close();
                conn.Dispose();
      

  7.   

    很感谢各位的帮忙..但是还是不行啊...
    那些字段全都是varchar型的.而且后面有的还有可能跟字母..
      

  8.   

    如果是varchar型的可以转换为数字型的再比较。
    后面有字母是什么意思啊?是说字段a有可能是这样的值吗:1974/000B,如果是的话,
    你要SQL查询1965/0005到1974/007之间的数据?后面是字母的要查出来吗?