|
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?
(comments are locked)
|
|
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. Gah. You must have submitted your answer just as I was starting on mine. Oh well...
Jan 11 '12 at 04:00 AM
ThomasRushton ♦
(comments are locked)
|
|
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.
(comments are locked)
|


Thanks Kev for getting my question to show the right number of underline characters. How did you do that? I obviously missed something about formatting questions on this site and was getting anything but what I wanted to show.
just formatted the output as 'code' : either highlight the text and click the code button, or prefix each line with 4 spaces