Two identical Queries are returning different results in where clause. The first query is with SQL parameter variable and the second query with a string value as mentioned below. The result of both queries should be the same as both have the same values but it is not happening. what could be the reason for that?
Declare @messageID AS INT=720987
Declare @replyfileType AS Varchar='Audio'
select VoiceMessageReply from MDBDetails where MessageID = @messageID and FileType=@replyfileType
select VoiceMessageReply from MDBDetails where MessageID = @messageID and FileType='Audio'
Result is as :- Query results
This declaration:
Is declaring a one character string, so it is equivalent to:
Always include the length when using strings in SQL Server!
I should note that if you printed out
@replyfileTypethe error would be obvious.