rq:=query2.fieldvalues['测试日期'];
SQLstr:=‘delete from table where 测试日期='''+datetimetostr(rq)+'''';

解决方案 »

  1.   

    rq:=query2.fieldvalues['测试日期'];
    SQLstr:=‘delete from table where 测试日期=cast('''+datetostr(rq)+''' as datetime) '
      

  2.   

    尝试:
    SQLstr:='delete from table where 测试日期='''+Cast(datetostr(rq) as date)+'''';SQLstr:='delete from table where 测试日期='+datetostr(rq);
      

  3.   

    用的cb或delphi吗?先把rq转换成字符串rq_str(cb 中)
    然后再
    SQLstr:='delete from table where 测试日期='''+Cast(rq_str as date)+'''';
      

  4.   

    直接用:delete from table where 测试日期=''' + rq + ''''
      

  5.   

    以上都有试了同样的错误“type mismatch in expression"是不是这个原因,其实完整的语句是:SQLstr:='delete from '''+tempcx+''' where 编号='''+bh+''' and 测试日期='''+datetostr(rq)+'''';高手在那???????????拜托各位了,实在是急啊
      

  6.   

    应该直接写没错啊第一你先看看你datetostr函数的生成结果是什么
    第二你最好把SQLSTR打出来给大家看看,因为你又是单引号又是两个单引号的我觉得可能最后是引号出了问题
    第三,可能是datetostr(rq)的输出结果不是一个日期
      

  7.   

    楼上的老兄,多谢了,可不可以帮我查一下,我现在没有一点头绪,我在线等SQLstr:='delete from '''+tempcx+''' where 编号='''+bh+''' and 测试日期='''+datetostr(rq)+'''';
      

  8.   

    SQLstr:='delete from '''+tempcx+''' where 编号='''+bh+''' and 测试日期='''+rq+'''';
      

  9.   

    为什么要加datatostr?测试日期不就是date型吗?
      

  10.   

    SQLstr:='delete from ' + tempcx + ' where 编号='''+bh+''' and 测试日期='''+datetostr(rq) + '''';
      

  11.   

    如果不加datatostr:编译的时候就出现此提示但是加了就在运行时出现
      

  12.   

    为什么要加datatostr?测试日期不就是date型吗?是啊,但SQLstr是string型啊
      

  13.   

    rq:=query2.fieldbyname['测试日期'].asstring;
    SQLstr:='delete from  where  测试日期='''+rq+'''';
      

  14.   

    我讲一个基本原则吧,你把SQL语句里所有的变量值全部转为字符型,然后再连成字符串。
    把SQL语句至当作是一个字符串,没有变量!
      

  15.   

    你把你的程序生成的SQL语句拷贝到SQL-SERVER中的视图里去检测一下!
      

  16.   

    编号字段为数值类型,bh为字符串,bh不是字符串转化为日期
    SQLstr:='delete from '+ tempcx + ' where 编号 = ''' + bh + ''' and 测试日期=''' + datetimetostr(rq,'yyyy-mm-dd') + '''';
    你试试