SQL 查找最近日期并计算出到今天的 WD

问题描述 投票:0回答:1

我有以下SQL

      SELECT    Case.casekey,Case.StartDate,letter_sent.OfferreceivedDate, letter_sent.QuestionnairereceivedDate, letter_sent.ClientDate,letter_sent.ReceivedDate 
        FROM       Case WITH (nolock) INNER JOIN
    LEFT OUTER JOIN letter_sent WITH (NOLOCK) ON Case.casekey = letter_sent.casekey
        WHERE
        letter_sent.OfferreceivedDate is not null and 
        letter_sent.QuestionnairereceivedDate is not null and  letter_sent.ClientDate is not null
        and letter_sent.ReceivedDate is not null
        ORDER BY Case.CaseStart DESC 

我有一个存储过程,它查看两个日期字段并计算它们之间的总工作日。我需要运行 SQL 查询,然后从每条记录的 5 个日期字段中获取最新日期,并在我的存储过程中使用它来计算该日期与今天之间有多少个工作日。我希望我已经说清楚了。

sql sql-server-2008
1个回答
0
投票

您可以使用

TOP 1
语句来获取最近的日期行

SELECT   TOP 1  Case.casekey,Case.StartDate,letter_sent.MortgageOfferreceivedDate, letter_sent.QuestionnairereceivedDate, letter_sent.ClientDate,letter_sent.ReceivedDate 
    FROM       Case WITH (nolock) INNER JOIN
LEFT OUTER JOIN letter_sent WITH (NOLOCK) ON Case.casekey = letter_sent.casekey
    WHERE
    letter_sent.MortgageOfferreceivedDate is not null and 
    letter_sent.QuestionnairereceivedDate is not null and  letter_sent.ClientDateis not null
    and letter_sent.ReceivedDate is not null
    ORDER BY Case.CaseStart DESC
© www.soinside.com 2019 - 2024. All rights reserved.