November 11, 2010 at 12:59 pm
Hi,
I have a variable @var bit and I assign -1 to that variable. When I execute SELECT @var I get 1. Why ? Thanks.
November 11, 2010 at 1:17 pm
In SQL Server the only three valid values for BIT is 1, 0 and NULL.
Only 0 will be interpreted as 0 and all other values will be treated as 1.
It's different from VB/Access and other pre-dotnet languages where you could have 0 and -1 as possible values for bit.
And, not to forget, it's totally up to you to decide what 0 and 1 means for you. Most people tend to use 1 as true and 0 as false.
N 56°04'39.16"
E 12°55'05.25"
November 11, 2010 at 1:24 pm
Because 1 bit of data only stores on/off, not "on/off/negative-on". Some use -1/0, which is essentially the same thing. Some allow 1/0/-1, but that means they're using more than a bit for a bit, because they have to have at least one more bit to store the sign, which kind of defeats the purpose of using a bit datatype.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply