标准表达式中的数据类型不匹配,ACCESS

时间:2017-02-10 11:15:08

标签: sql ms-access

我写了这个查询

SELECT dayar 
FROM   dayarim 
WHERE  ( Year(enter_month) = Year(Now()) ) 
    OR ( Year(enter_month) < Year(Now()) 
         AND Year(left_month) >= Year(Now()) ) 
       AND ( Datediff('m', Iif(Year(enter_month) = Year(Now()), enter_month, 
                                 '1/1/' + Year(Now())), Now()) * 50 ) < ( 
           Datediff('m', '1/1/' + Year(Now()), Now()) * 50 ) 

我收到了这个错误:

  

标准表达式中的数据类型不匹配

我在谷歌搜索,我发现此错误意味着等于表达式与字段数据类型不匹配

我的表:

https://i.gyazo.com/3b1b3a4e948c3ebdd0054c8db4fc7516.png

我的数据:

https://i.gyazo.com/7c52b15914873e5c2eac3f704b156a90.png

我正试图找到没有付款的名单 他们需要每月支付50美元,因此结果将是没有支付的名单

修改 由于古斯塔夫的评论我明白我会检查他们支付的金额

 SELECT dayar 
 FROM   dayarim 
 WHERE  ( Year(enter_month) = Year(Now()) ) 
    OR ( Year(enter_month) < Year(Now()) 
         AND Year(left_month) >= Year(Now()) ) 
       AND (SELECT Sum(payments.sum) 
            FROM   payments 
            WHERE  payments.paymentdate > '1/1' + Year(Now()) 
                   AND paymentdate <= Now() 
                   AND payerid = dayarim.id) < ( 
           Datediff('m', '1/1/' + Year(Now()), Now()) * 50 ); 

但仍然得到同样的错误

2 个答案:

答案 0 :(得分:0)

尝试:

SELECT 
    dayar 
FROM   
    dayarim 
WHERE
   Year(Nz(left_month, Date())) >= Year(Date())
   AND
   Year(enter_month) <= Year(Date()) 
   AND
   (SELECT Sum(payments.sum) 
    FROM   payments 
    WHERE  Year(payments.paymentdate) = Year(Date())
        AND payerid = dayarim.id) < (Month(Date()) - 1) * 50

答案 1 :(得分:0)

正确的查询是:

SELECT dayar 
FROM   dayarim 
WHERE  ( Year(enter_month) = Year(Now()) ) 
    OR ( Year(enter_month) <= Year(Now()) 
         AND Year(left_month) = Year(Now()) ) 
       AND (SELECT Sum(payments.sum) 
            FROM   payments 
            WHERE  payments.paymentdate > Dateserial(Year(Now()), 1, 1) 
                   AND paymentdate <= Now() 
                   AND payerid = dayarim.id) < ( Datediff('m', 
                                                 Dateserial(Year(Now( 
                                                 )), 
                                                 1, 1), Now()) * 50 ); 

我只是用DateSerial函数替换日期的bilding及其作品

感谢Joe4