Sorry for the somewhat trivial question, but why does
select ('https://stackoverflow.com/users/' + str(Id)) as Link
from Users
where DisplayName = 'Jon Skeet';
when entered into the Data Explorer return
https://stackoverflow.com/users/ 22656
instead of
https://stackoverflow.com/users/22656
?
According to Microsoft's documentation on T-SQL's + operator,
'book' + 'case'
should give
'bookcase'
not
'book case'
and according to the Data Explorer documentation, the SQL-flavor used in the Stack Exchange Data Explorer is indeed T-SQL.
Some additional experiments:
select str(42);
returns "42", without extra spaces (see EDIT below).
select ('foo' + 'bar');
returns "foobar", also without spaces.
select ('foo' + '42');
returns "foo42", so it doesn't treat digits specially or anything like that.
To me, it looks as if basic semantic compositionality principle is violated. What am I missing here?
EDIT The problem turned out to be the wrong assumption that
select str(42);
returns "42". It actually returns
" 42"
but the spaces are ignored by the browser-based GUI.
Here is another example that demonstrates the problem more clearly:
select 'foo' + str('42');
seems to return
"foo 42"
but it actually returns
"foo 42"
as can be seen in this query:
select LEN('foo' + str('42'));
which returns 13 (not 5 and also not 6). Many thanks @lad2025 for pointing this out.
So, it was mostly an "optical illusion" caused by a somewhat inaccurate representation of string-results in the browser.
strsays: "A short float_expression is right-justified in the specified length, and a long float_expression is truncated to the specified number of decimal places. For example, STR(12,10) yields the result of 12. This is right-justified in the result set."int.STRfunction-) Ok, so, theselect str(42);returns"---------42"instead of"42", but the spaces are ignored by the browser-based GUI. Here is another example that demonstrates the problem more clearly: select 'foo' + str('42'); seems to return"foo-42", but it actually returns"foo--------42", as can be seen in this query: select LEN('foo' + str('42')); which returns13(not5and also not6). Many thanks @lad2025 for pointing this out.