Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Bit by bit Rate Topic Display Mode Topic Options
Author
 Message
 Posted Thursday, January 28, 2010 4:26 AM
 SSC Veteran Group: General Forum Members Last Login: Monday, October 7, 2013 4:37 AM Points: 256, Visits: 224
 This should worth of 100 points
Post #855071
 Posted Thursday, January 28, 2010 6:21 AM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 11:07 AM Points: 2,900, Visits: 2,687
 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
Post #855133
 Posted Thursday, January 28, 2010 7:40 AM
 Hall of Fame Group: General Forum Members Last Login: Monday, November 10, 2014 12:05 PM Points: 3,969, Visits: 3,648
 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.
Post #855247
 Posted Thursday, January 28, 2010 7:58 AM
 SSC Eights! Group: General Forum Members Last Login: Wednesday, November 23, 2016 2:20 AM Points: 928, Visits: 786
 Dave62 (1/28/2010)I think it is because the BIT type is supposed to represent True (1) or False (0) rather than integers.DaveAh! 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.
Post #855271
 Posted Thursday, January 28, 2010 8:07 AM
 SSCrazy Group: General Forum Members Last Login: Wednesday, November 30, 2016 2:06 AM Points: 2,251, Visits: 8,029
 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 BITSET @bit = 'false'PRINT @bitSET @bit = 'true'PRINT @bit
Post #855288
 Posted Thursday, January 28, 2010 8:09 AM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 11:07 AM Points: 2,900, Visits: 2,687
 A little more information about the BIT type. The bit type has 3 states: NULL, 0, and 1.When first declared and unset a NULL will be returned.Only a 0 or the string 'False' will return a 0.Any positive or negative number or the string 'True' will return a 1.Any string other than 'True' or 'False' will return an error.The following script illustrates the points above:`Set NOCOUNT OnDeclare @blnFlag bitSelect @blnFlag As [Unset Returns]Set @blnFlag = 0Select @blnFlag As [Set to 0 Returns]Set @blnFlag = 144Select @blnFlag As [Set to 144 Returns]Set @blnFlag = -144Select @blnFlag As [Set to -144 Returns]Set @blnFlag = 'False'Select @blnFlag As [Set to 'False']Set @blnFlag = 'True'Select @blnFlag As [Set to 'True']Set @blnFlag = 'Dave'Select @blnFlag`The following resuts are returned:Unset Returns-------------NULLSet to 0 Returns----------------0Set to 144 Returns------------------1Set to -144 Returns-------------------1Set to 'False'--------------0Set to 'True'------------1Msg 245, Level 16, State 1, Line 22Conversion failed when converting the varchar value 'Dave' to data type bit.Dave
Post #855289
 Posted Thursday, January 28, 2010 10:04 AM
 Ten Centuries Group: General Forum Members Last Login: Monday, June 6, 2016 1:51 PM Points: 1,400, Visits: 3,059
 Dave62 (1/28/2010)A little more information about the BIT type. The bit type has 3 states: NULL, 0, and 1. . . . I don't think that's quite right. It's not that a BIT datatype has three states -- wouldn't that be a "trit"? -- but that ANY data element may be designated as nullable or not, and nullable is the default case for columns and the only choice for variables. If a column is nullable, there's an internal switch maintained to designate the field as null.
Post #855435
 Posted Thursday, January 28, 2010 11:38 AM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 11:07 AM Points: 2,900, Visits: 2,687
 john.arnott (1/28/2010)...It's not that a BIT datatype has three states -- wouldn't that be a "trit"? -- but that ANY data element may be designated as nullable or not, and nullable is the default case for columns and the only choice for variables. If a column is nullable, there's an internal switch maintained to designate the field as null.All true but the end result is 3 states because the database will return a NULL if the field is nullable, has no default setting, and has not been set. Some applications are handling all 3 states now by displaying a checkbox as checked, unchecked, or "highlighted" if the database returns 1, 0, or NULL respectively.Dave
Post #855526
 Posted Thursday, January 28, 2010 2:22 PM
 SSC-Enthusiastic Group: General Forum Members Last Login: Tuesday, August 16, 2016 2:01 PM Points: 121, Visits: 810