Ok. Good point. And good advice. I tried DATALENGTH on a:
tinyint variable assigned the value of 1
smallint variable assigned the value of 1
int variable assigned the value of 1
bigint variable assigned the value of 1
To represent the number 1, it only takes 1 byte. Instead of getting 1 as the answer in all 4 cases above, I got the number of bytes set aside by the variable which is determined by the variables data type. So I got:
But what about this. Instead of returning the number of bytes set aside by a variable (dependent on the data type), what if I wanted to return the number of bytes that is occupied by the value stored in the variable? If that were possible, in all four cases above the value returned would be 1 since 1 byte is all it takes to represent the value of 1 and I am assigning the value of 1 to a variable in all four cases above. Is there a way to return the number of bytes occupied by the value assigned to a variable?