czpsql1:= 'SELECT * FROM 操作票表 where   '         +
                           '厂站号 = '+inttostr(Datacon.g_bdzbh)+'  '+
                           ' and  类型 = '+inttostr(Datacon.g_lxbh)+' '     +
                           ' and 保存时间 like '''+trim(Datacon.g_year)+'-'+trim(Datacon.g_mou)+'-'+trim(Datacon.g_date)+'%'''+
                           '  order by 序号';时间查不出来,执行后没有结果
  'SELECT * FROM 操作票表 where   厂站号 = 0   and  类型 = 1  and 保存时间 like '2003-07-1%'  order by 序号'

解决方案 »

  1.   

    跟踪一下,下面这些都有值么???
    Datacon.g_bdzbh
    Datacon.g_lxbh
    Datacon.g_year
    Datacon.g_mou
    Datacon.g_date
      

  2.   

    不知道时间能不能like,反正我是没有用过时间的like,感觉也没有意义。
      

  3.   

    不要对时间用like,因为格式不同
    你可以
    1 用 convert(varchar,保存时间,120) like '2003-07-1%'
    2 或者
    'SELECT * FROM 操作票表 where   厂站号 = 0   and  类型 = 1  and 保存时间 between '2003-7-10' and '2003-7-20' order by 序号'
      

  4.   

    SELECT * FROM 操作票表
     where 厂站号 = '0'
       and 类型 = '1'
       and 保存时间 like '2003-07-1%'
     order by 序号这样行吗?
    建议你先使用数据库的相关执行SQL语句工具(ORACLE--SQLPLUS)试验一下生成的SQL语句,然后改进。
      

  5.   

    Datacon.g_bdzbh
    Datacon.g_lxbh
    Datacon.g_year
    Datacon.g_mou
    Datacon.g_date我是字符,         Datacon.g_year :=combobox2.Text ;  //年
             Datacon.g_mou  :=combobox3.Text ;   //月
             Datacon.g_date :=SpinEdit1.Text ;    //日
      

  6.   

    ACCESS数据库是时间表示是#2000-1-1#,不是'2000-1-1'。这只是错误之一。我还是认为日期型不能like,转成字符型吧
      

  7.   

    czpsql1:= 'SELECT * FROM 操作票表 where  厂站号 = '''+inttostr(Datacon.g_bdzbh)+''' and  类型 = '''+inttostr(Datacon.g_lxbh)+''' and 保存时间= '''+trim(Datacon.g_year)+'-'+trim(Datacon.g_mou)+'-'+trim(Datacon.g_date)+''' order by 序号';
      

  8.   

    czpsql1:= 'SELECT * FROM 操作票表 where  厂站号 = '''+inttostr(Datacon.g_bdzbh)+''' and  类型 = '''+inttostr(Datacon.g_lxbh)+''' and 保存时间= '''+trim(Datacon.g_year)+'-'+trim(Datacon.g_mou)+'-'+trim(Datacon.g_date)+''' order by 序号';