Reference:WHEN (Entity SQL)
參考回傳bool值欄位的範例卻錯誤
CASE WHEN AVG({25,12,11}) < 100 THEN TRUE ELSE FALSE END以下是自已的測試結果(錯誤的解):
(CASE
WHEN dbo.HomeWorkAssign.HomeWorkAssignModifyDate is null THEN True ELSE False END)
將欲回傳的bool值加單引號就正常了,或著將值設為1 or 0,不過asp.net 繫結時都需要Convert.ToBoolean轉換才能變成bool值給元件使用
(CASE WHEN dbo.HomeWorkAssign.HomeWorkAssignModifyDate is null THEN 'True' ELSE 'False' END)
最後的處理方法
(CASE
WHEN dbo.HomeWorkAssign.HomeWorkAssignModifyDate is null THEN 'True'
WHEN DATEDIFF(s ,
dbo.HomeWorkAssign.HomeWorkAssignModifyDate,
dbo.HomeWorkImages.HomeWorkImagesCreateDate
) > 0
Then 'True'
ELSE 'False'
END)
References:What is the best way to convert an int or null to boolean value in an SQL query?
沒有留言:
張貼留言
留個話吧:)