例如有一张表,有三个字段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之间的数据?
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之间的数据?
between cast(REPLACE('1965/0005','/','') as int) and
cast(REPLACE('1974/0007','/','') as int)
试试这个,没有调试过,提供个思路,希望有点帮助:
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)
(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)
between cast(REPLACE('1965/0005','/','') as int) and
cast(REPLACE('1974/0007','/','') as int)
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();
那些字段全都是varchar型的.而且后面有的还有可能跟字母..
后面有字母是什么意思啊?是说字段a有可能是这样的值吗:1974/000B,如果是的话,
你要SQL查询1965/0005到1974/007之间的数据?后面是字母的要查出来吗?