我想在兩種情況下過濾SQL Server中的記錄。我正在爲此寫一個存儲過程。如何在SQL Server中篩選器值爲NULL時篩選條件上的記錄?
這是我的查詢
// Parameters
@carNo AS INT
@carEngineNo AS INT = null // this is optional
Select *
From CarLog
//Some Joins
Where
CarLog.car_no = carNo
// here I want condition, I tried this but there is some syntax error
And CASE
When @carEngineNo IS NOT NULL THEN CarLog.engine_no= carEngineNo
WHEN @carEngineNo IS NULL THEN CarLog.engine_no = CarLog.engine_no
END
我怎樣才能做到這一點?
'//這裏我想要條件,我這樣做,但有一些語法錯誤'什麼是語法錯誤。同時顯示拋出錯誤的查詢。 –