-3

我想知道是否有人能够指出以下代码的问题。特别是 dateDiff 部分。我要做的是找出发送发票和存款日期之间的差异(以天为单位)。如果存款日期为空,我想使用今天的日期。很简单,我还以为...

$rs = mysql_query("SELECT i.dateSent
    , i.dateDeposit
    , i.invoiceID
    , i.gstValue
    , i.invoiceValue AS invoiceTotal
    , p.projectValue
    , i.invoiceNumber
    , p.projectName
    , p.projectNumber
    , p.projectID
    , c.clientName
    , c.clientCode
    , c.clientID
    , DATEDIFF(i.dateSent, CASE WHEN i.dateDeposit IS Null Then GetDate() ELSE i.dateDeposit) as numbDays

FROM cms_invoices i

LEFT JOIN cms_projects p ON p.projectID = i.projectID
LEFT JOIN cms_clients c ON p.clientID = c.clientID

ORDER BY i.dateDeposit ASC, c.clientName ASC
");

在这个阶段,结果是没有结果。dateDiff 行中断查询。精氨酸。

谢谢,@rrFive

4

1 回答 1

2

好像你错过了一个END

... DATEDIFF(i.dateSent, 
    CASE
        WHEN i.dateDeposit IS NULL
            THEN GetDate()
        ELSE i.dateDeposit
     END) AS numbDays
于 2013-01-25T23:29:15.163 回答