如何获取存储过程中日期之间的数据总和?

时间:2018-05-28 01:20:37

标签: sql-server stored-procedures

大家好,我怎么能做到这一点没有错误?

CREATE PROCEDURE sp_per_transaction
    @Datefrom DATETIME,
    @Dateto DATETIME
AS
BEGIN

    SELECT 
        Trans,
        SUM (ISNULL(DI_SC,0)) AS "Sum of  SC",
        SUM (ISNULL(DI_PWD,0)) AS "Sum of  PWD",
        SUM (ISNULL(DI_Student,0)) AS "Sum of  Student",
        SUM (ISNULL(VATable,0)) AS "Sum of  VATable",
        SUM (ISNULL(VAT,0)) AS "Sum of  VAT",
        SUM (ISNULL(VATExempt,0)) AS "Sum of  VATExempt",
        SUM (ISNULL(GrossAmount,0)) AS "Sum of  GrossAmount"
    FROM [ATIBTicketingDB_test2].[dbo].[Transaction]

    WHERE BETWEEN DatePosted  @Datefrom AND @Dateto

    GROUP BY Trans;

END

编辑:这是我的错误 - 在DatePosted @Datefrom和@Dateto之间的比赛

1 个答案:

答案 0 :(得分:0)

你的where子句应该是:

WHERE DatePosted BETWEEN @Datefrom AND @Dateto 

不是

WHERE BETWEEN DatePosted  @Datefrom AND @Dateto