select * from tabel1 where (nian*100+yue) between int1 and int2
int1和int2是整型变量
这个sql语句有什么错误
nian和yue数据类型都为int

解决方案 »

  1.   

    no problem
    create table t(nian int,yue int)insert into t select 2004,1
    union select 2003,2
    union select 2005,5select * from t where (nian*100+yue) between 200102 and 200603nian        yue         
    ----------- ----------- 
    2005        5
    2003        2
    2004        1
      

  2.   

    select * from tabel1 where (nian*100+yue) between int1 and int2这一句在sql server中一定没有问题。问题可能出现有空值.
      

  3.   

    出现列名int1无效我的完整的语句是这样的with adoquery2 do                   
            begin
               close;
               sql.Clear;
               sql.Add('insert into kaoqin_chuqinjilu_temp');
               sql.Add(' select * from kaoqin_chuqinjilu where');
               sql.Add(' 员工编号 in (select 员工编号 from personal where 部门='''+bm.Text+''')');
               sql.Add(' and (年度*100+月份) between int1 and int2');
               execsql;
            end;
      

  4.   

    用showmessage(adoquery2.SQL.Text)
    把SQL语句显示出来就知道啦
      

  5.   

    with adoquery2 do                   
            begin
               close;
               sql.Clear;
               sql.Add('insert into kaoqin_chuqinjilu_temp');
               sql.Add(' select * from kaoqin_chuqinjilu ');
               sql.Add('where 员工编号 in (select 员工编号 from personal where 部门='''+bm.Text+''')');
               sql.Add(' and (年度*100+月份) between int1 and int2');
               execsql;
            end;
      

  6.   

    with adoquery2 do                   
            begin
               close;
               sql.Clear;
               sql.Add('insert into kaoqin_chuqinjilu_temp');
               sql.Add(' select * from kaoqin_chuqinjilu ');
               sql.Add('where 员工编号 in (select 员工编号 from personal where 部门='''+bm.Text+''')');
               sql.Add(' and (年度*100+月份) between ISNULL(int1,0) and ISNULL(int2,0)');
               execsql;
            end;