|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, March 12, 2010 3:15 AM
Points: 66,
Visits: 78
|
|
I try this out with @bit = 0 it gives message "no" if @bit = -500 ,it gives message "yes", if @bit = -1 then also it gives "yes".
The Explanation Given for Answer : Bit constants are represented by the numbers 0 or 1, if a number larger than one is used, it is converted to one. but what about the values less than 1, still they consider as 1
Please explain me more about the negative values used for bit datataype.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 7:14 AM
Points: 196,
Visits: 60
|
|
for bit datatype, any value which in non-zero is converted to bit 1.
try this you will get better understading,
declare @bit bit set @bit = -0 select @bit
declare @bit bit set @bit = +0 select @bit
as mathematical there is no concept of +/- 0 ..is for only understading purpose.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
why is'nt BIT treated like other datatypes?
"Keep Trying"
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, April 25, 2013 2:25 PM
Points: 94,
Visits: 29
|
|
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 am exactly feeling the same. I think a database should not be so forgiving. In programming languages this may be treated as boolean but here it should be a numeric range and any thing else than 0 or 1 should throw an error.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
Marry Krissmess (2/5/2010) In programming languages this may be treated as boolean but here it should be a numeric range and any thing else than 0 or 1 should throw an error.
Why? The Bit datatype is a boolean, so why is it so surprising that it is treated as such?
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 8:43 PM
Points: 10,989,
Visits: 10,533
|
|
Marry Krissmess (2/5/2010) I am exactly feeling the same. I think a database should not be so forgiving. In programming languages this may be treated as boolean but here it should be a numeric range and any thing else than 0 or 1 should throw an error. Try it with the strings 'true' and 'false' - that will really upset you!
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 8:43 PM
Points: 10,989,
Visits: 10,533
|
|
ChiragNS (1/31/2010) why is'nt BIT treated like other datatypes? It is. The value supplied is implicitly converted to a BIT, according to the conversion rules.
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, October 26, 2012 12:30 PM
Points: 20,
Visits: 27
|
|
I think": " Converting to bit promotes any nonzero value to 1" not greater than zero only Because DECLARE @bit BIT SET @bit = -14
IF @bit = 1PRINT 'yes'ELSE PRINT 'no'
is also give yes.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 8:43 PM
Points: 10,989,
Visits: 10,533
|
|
shini2007 (9/16/2010) I think":" Converting to bit promotes any nonzero value to 1" not greater than zero only Because DECLARE @bit BIT SET @bit = -14
IF @bit = 1PRINT 'yes'ELSE PRINT 'no'
is also give yes. Non-zero does not mean greater than zero, it means not zero. -14 is not zero, so it is converted to 1, as I said. Does that make sense?
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|