duangu4943 2014-05-04 10:23
浏览 61

如何在ODBC中转换MS Access的SQL查询

Here is table images which is given below

enter image description hereenter image description here

My Query is give below,

$DB2->query("SELECT CHECKINOUT.USERID,USERINFO.CardNo FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE CHECKTIME BETWEEN '$start_date' AND '$tommorow' AND USERINFO.CardNo <> NULL")

I want to do query in ODBC Like below

$DB2->query("SELECT CHECKINOUT.USERID,USERINFO.CardNo FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE format(CHECKTIME, 'dd/mm/yyyy') BETWEEN '$start_date' AND '$tommorow' AND USERINFO.CardNo <> NULL")

But The Query for ODBC it is not work perfectly, it has come all date data with date difference data.

How to make perfect query in ODBC FOR MS ACCESS Database.

Please give me any solution.

  • 写回答

1条回答 默认 最新

  • dqqfuth6736 2014-05-06 23:24
    关注
        SELECT CHECKINOUT.USERID,USERINFO.CardNo FROM CHECKINOUT
        INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID
        WHERE CHECKTIME
        BETWEEN #$start_date# AND #$tommorow# AND USERINFO.CardNo <> NULL
    

    I see from your screen images that CHECKTIME is a datetime data type. If you are sending the query to MS-Access, the dates must be surrounded by pounds signs (#) and not single quotes. You don't need to format them as string, the default for using a date will be midnight (00:00) unless you specify otherwise.

    The best solution is to paste this query into the MS-Access query designer and make sure it gives you the results you expect. Failing that, create the query in the MS-Access designer and look at the SQL it returns for format.

    Note if you say between startdate and tomorrow that would between, for example 6-May-2014 at 00:00 through 7-May-2014 at 00:00. So it depends what you mean by "tomorrow" (beginning of the day or end of the day).

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行