December 3, 2018 at 10:03 pm
Comments posted to this topic are about the item Fun addition
December 3, 2018 at 10:48 pm
Nice, easy question, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
โlibera tute vulgaris exโ
December 4, 2018 at 1:24 am
Datatype precedence!! :ermm:
Where is my coffee, please! ๐
December 4, 2018 at 7:22 am
I agree about the issue being datatype precedence. Here's a useful list:
https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-precedence-transact-sql?view=sql-server-2017
December 4, 2018 at 8:29 am
I was about to complain that the question should have specified which version of SQL Server. Otherwise the correct answer is either '2" or "an error".
But I looked it up. I hadn't realized that += had been added as early as SQL Server 2008. So every supported release of SQL Server will allow this.
December 4, 2018 at 8:30 am
Thanks, nice question.
Btw this returns 11 (or rather, '11'):DECLARE @s-2 VARCHAR(10) = '1'
SELECT @s-2 += '1'
SELECT @s-2
- webrunner
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
December 4, 2018 at 2:32 pm
Hah hah, very witty - thank you, Steve!
December 6, 2018 at 8:39 am
simples ๐
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
December 18, 2018 at 11:40 pm
I must admit that I'm struggling with this question. The Concatenation answer of '11' makes more sense to me than the conversion into Int. I ran this this on a 2016 SSMS Version and got '11'.
December 19, 2018 at 9:47 am
I suppose MS has implicit cast order documented somewhere. But this inspired me to do some testing. Where @s-2 is varchar and @i is int.
@s-2 += '1' = '11'
@s-2 += 1 = 2
@i += '1' = '11'
@i += 1 = 2
I guess that's a bit intuitive. The type of the rhs value is being used to decide whether + is a string operator or a numeric operator.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply