January 27, 2010 at 8:12 pm
Comments posted to this topic are about the item Bit by bit
January 27, 2010 at 8:13 pm
Easy one.
SQL DBA.
January 27, 2010 at 8:29 pm
Good question. Tests the basic 🙂
M&M
January 27, 2010 at 10:07 pm
Points for taking ... 😛
January 27, 2010 at 10:10 pm
Bhavesh_Patel (1/27/2010)
Points for taking ... 😛
Makes up for yesterdays (though points were awarded anyway...)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 27, 2010 at 10:16 pm
Thanks for the question.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
January 27, 2010 at 11:08 pm
easy one 😀
January 28, 2010 at 2:05 am
"if a number larger than one is used, it is converted to one."
I thought the actual explanation was that anything other than 0 (false) is treated as true and hence is stored as 1. So a number larger than 1 becomes 1, but so does any number less than 1, apart from 0.
January 28, 2010 at 2:19 am
OK. I am in the 17% who got it wrong - I replied "Error". And now I know. But will somebody kindly explain why BIT is treated any differently to TINYINT, SMALLINT, INT, etc. It is, after all, only a type that has a range of valid values. If the others report an overflow error when I try to assign values outside their permitted range, why not BIT also?
January 28, 2010 at 2:32 am
Here's a slightly better reference
http://msdn.microsoft.com/en-us/library/ms191530(SQL.90).aspx#_bit
"Converting to bit promotes any nonzero value to 1"
January 28, 2010 at 4:26 am
This should worth of 100 points 🙂
January 28, 2010 at 6:21 am
Bob Cullen-434885 (1/28/2010)
OK. I am in the 17% who got it wrong - I replied "Error". And now I know. But will somebody kindly explain why BIT is treated any differently to TINYINT, SMALLINT, INT, etc. It is, after all, only a type that has a range of valid values. If the others report an overflow error when I try to assign values outside their permitted range, why not BIT also?
I think it is because the BIT type is supposed to represent True (1) or False (0) rather than integers.
Dave
January 28, 2010 at 7:40 am
Toreador (1/28/2010)
"if a number larger than one is used, it is converted to one."I thought the actual explanation was that anything other than 0 (false) is treated as true and hence is stored as 1. So a number larger than 1 becomes 1, but so does any number less than 1, apart from 0.
I agree. Any numeric value other than 0. It will also apply to -1.3434. It does not have to be larger than 0.
January 28, 2010 at 7:58 am
Dave62 (1/28/2010)
I think it is because the BIT type is supposed to represent True (1) or False (0) rather than integers.
Dave
Ah! So a BOOLEAN type, then. That's different, and if so should also require that the language provides proper TRUE and FALSE keywords, rather than hijacking numeric values like 0, 1, pi or whatever.
January 28, 2010 at 8:07 am
Bob Cullen-434885 (1/28/2010)
Ah! So a BOOLEAN type, then. That's different, and if so should also require that the language provides proper TRUE and FALSE keywords, rather than hijacking numeric values like 0, 1, pi or whatever.
True and False are also accepted.
DECLARE @bit BIT
SET @bit = 'false'
PRINT @bit
SET @bit = 'true'
PRINT @bit
Viewing 15 posts - 1 through 15 (of 29 total)
You must be logged in to reply to this topic. Login to reply