March 2, 2020 at 12:00 am
Comments posted to this topic are about the item Casting Tiny Numbers
March 2, 2020 at 3:00 pm
Good basic question, Steve. My only objection would be the title of the question itself because this also occurs for much larger numbers and larger VARCHARs.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 2, 2020 at 6:53 pm
While I agree with Jeff, it doesn't apply to all larger numbers. TINYTINT, SMALLINT, and INT's have the same behavior but bigints throw an error instead.
As for the VARCHAR value, as long as it is 1 or more under the number of digits in the variable you will get the answer (or a derivative of it) from the QOTD.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
March 2, 2020 at 7:34 pm
This question isn't designed to cover all possibilities. Writing questions like that is hard and fraught with perils. You are welcome to submit your own questions about other types of numerical values.
March 2, 2020 at 8:08 pm
I wasn't trying to rag on you Steve. I was just commenting on the different data types (at least in SQL 2008 R2 which I tested it in) that give that result.
Testing it against all SQL versions and all datatypes would be a nightmare. And what happens when a SP or CU changes the behavior? I like the question and the link is good too. Tells you what to expect with most data types!
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
March 2, 2020 at 8:51 pm
This question isn't designed to cover all possibilities. Writing questions like that is hard and fraught with perils. You are welcome to submit your own questions about other types of numerical values.
Oh no... I get that. It was a good question.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 3, 2020 at 6:20 am
This has bitten me in the past (front-end developers not making provision for very large integers).
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
October 13, 2020 at 8:05 am
Thanks for the Question! That was unexpected.
/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply