I have noticed the LEFT TSQL statement within SSMS (Results to Text) returns a different length column header underline if you use a declared integer variable rather than a hard coded integer as can be seen in the following example:
Does anyone know why this is? Also why does the first example have four underline characters rather than the expected three?
The number of underlines seems to be determined by the largest of:
4 seems to be the minimum : try
The reason for the second one returning 6, is that at parse time, there is no idea of what @x is, but the max it could be is 6 (length of 'stuart'), so that is used.
Nothing specific to the LEFT function at all.
If you try
you get a line of 18
If you try
you still get 4
Try fiddling with other select statements, and you quickly find that integer columns are built to the length of the maximum number that can be held, and other similar limits elsewhere.
Unless... the column name is longer than the output - in which case the column name length takes precedence.
Why this is? So that the data can be formatted on the fly before all results are back.
answered Jan 11, 2012 at 03:59 AM