我有以下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 个日期字段中获取最新日期,并在我的存储过程中使用它来计算该日期与今天之间有多少个工作日。我希望我已经说清楚了。
您可以使用
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