我们如何在date()函数中使用dateadd函数

时间:2016-02-08 06:32:22

标签: sql ibatis

我希望获得两个日期之间的价值。这里创建的是' 2016-02-08 10:55:23'即日期和时间。这个查询效果很好。

select  E.Id as StaffId,
        SUM(IC.AmountReceived) as totalAmount,INV.InvoiceType as AccountType
from invoice_collection IC,employee E ,invoice INV
where IC.CollectedBy=E.id and IC.OperatorCode=#operatorCode#
        and INV.InvoiceNo=IC.InvoiceNo and E.Id=#staffId#
        and TxnDate > #CreatedOn#
group by INV.InvoiceType;

问题 当我按照下面的显示修改我的代码时,它不会显示任何值。

select  E.Id as StaffId,
        SUM(IC.AmountReceived) as totalAmount,INV.InvoiceType as AccountType
from invoice_collection IC,employee E ,invoice INV
where IC.CollectedBy=E.id and IC.OperatorCode=#operatorCode#
            and INV.InvoiceNo=IC.InvoiceNo and E.Id=#staffId#
            and TxnDate > #CreatedOn# and TxnDate < date(dateadd(day,1,#CreatedOn#))
group by INV.InvoiceType;

1 个答案:

答案 0 :(得分:0)

试试这个

TxnDate > #CreatedOn# AND TxnDate < DATEADD(d,DATEDIFF(day,0,dateadd(day,1,#CreatedOn#)),0)