SELECT *
FROM UsersMedicalSurgicalHistory UMSH INNER JOIN CCDTransaction CT on
UMSH.SurgicalHistoryId = CT.RowId
WHERE (
(CASE
WHEN LEN(UMSH.DateOfProcedure)<=4 THEN UMSH.DateOfProcedure
WHEN LEN(UMSH.DateOfProcedure)=0 THEN UMSH.DateOfProcedure
END
=
CASE WHEN @CodeFilter3 IS not null THEN @CodeFilter3
ELSE UMSH.DateOfProcedure end)
OR
(CASE
WHEN LEN(UMSH.DateOfProcedure)>4 THEN
CONVERT(datetime,UMSH.DateOfProcedure,101)
ELSE GETDATE()
END
=
CASE WHEN @CodeFilter2 IS not null THEN @CodeFilter2
ELSE GETDATE()
END)
)
所以這個問題就像CASE表達式可以在where子句
格式化您的代碼。 – CollinD
我不認爲你可以做到這一點。 –
@pavankumar,你不能比較任何隨機猜測與任何其他隨機猜測...其中一方必須是恆定的 – Vikrant