简而言之,这是我的查询和错误消息:
SELECT cs.CaseId, cs.ClientId,
DATEDIFF(dd, SentD.answer, FirstGrpAct.StartDate) AS NoOfDays
FROM vCases Cs
INNER JOIN (<...>) AS FirstGrpAct ON FirstGrpAct.CaseId = Cs.CaseId
INNER JOIN #tmpProgramAnswers Ref ON Ref.CaseId = Cs.CaseId
INNER JOIN #tmpProgramAnswers SentD ON SentD.CaseId = Cs.CaseId
WHERE DATEDIFF(dd, FirstGrpAct.StartDate, '2012-04-02') <= 0
错误:消息242,级别16,状态3,行1转换varchar 数据类型为日期时间数据类型导致超出范围的值。
SELECT
Cs.CaseId, cs.ClientId,
sentd.Answer,
FirstGrpAct.StartDate,
(case when isdate(SentD.Answer) = 0 then '9999999' else SentD.answer end ),
DATEDIFF(dd, (case when isdate(SentD.Answer) = 0 then '1900-01-01' else SentD.answer end ), FirstGrpAct.StartDate) AS NoOfDays
--DATEDIFF(dd, SentD.answer, FirstGrpAct.StartDate) AS NoOfDays
结果很奇怪。没有9999999返回。 我甚至在主查询中放置了前1名,但得到了同样的错误。
请指教。 请多谢,