I am trying to perform the following query in SQL server:
declare @queryWord as nvarchar(20) = 'asdas'
SELECT * FROM TABLE_1
WHERE (ISDATE(@queryWord) = 1)
AND TABLE_1.INIT_DATE = CONVERT(Date, @queryWord)
This obviously causes an error because 'asdas' cannot be converted to Date
. Although, I was expecting a different behavior. That is, because ISDATE(@queryWord) = 1
is false, I was expecting SQL to do not check the second condition, but apparently, it does.
I know there are some other ways to perform this query but this is not my question. I wonder if there is some way to do not check the second condition is the first one does not satisfy. I am curious because I thought that SQL already did this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…