Good question and thanks to Oleg for the more detailed explanation.
@nakul: no excuses about having no time to do the detailed reasoning 🙂 Post your question a few days later then, after you've done the research.
A small question for the experts: why isn't SELECT DATALENGTH(@TestVariable2) equal to 5? BOL says for the varchar datatype:
The storage size is the actual length of data entered + 2 bytes
The 2 extra bytes are used for storing the effective lenght of the string. Why doesn't datalength show these bytes?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP