This post is related to how the Case/When statement return value after the executing condition available.
Recently I am working on the query where I have to sort data based on the user input but each column in table has different datatype. So to meet with this type of requirement I use case when.. block of the sql server. something as below..
there is not syntax error when you check for the syntax error but when execute code you find there is error
ERROR:Conversion failed when converting datetime from character string.
the problem here is first two having databype Varchar and last one having datatype DateTime. So when you executing its found that one branch having datetime so its gives error even its not executing that.
So to avoid this problem you require to convert dateTime to the string