April 3, 2010 at 11:10 am
Good question today - a nice variation on the convert-to-BIT questions of the past. I will freely admit to guessing on this one!
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 3, 2010 at 5:21 pm
It is learning about things like this....one little BIT at a time that make me better and better. Thanks.
April 3, 2010 at 5:53 pm
dbowlin (4/3/2010)
It is learning about things like this....one little BIT at a time that make me better and better. Thanks.
Ha ha - good one!
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
April 3, 2010 at 10:36 pm
Simple and easy one.
SQL DBA.
April 3, 2010 at 10:40 pm
Easy but brushing up the knowledge
Thanks
John
April 4, 2010 at 10:09 pm
Good QOD.This Question gives good information about bit datatypes.
when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.
declare @bit bit
set @bit='233677788778'
select @bit
This gives 1 as output.
declare @bit bit
set @bit='00000'
select @bit
This gives 1 as output.
declare @bit bit
set @bit=' '
select @bit
This gives 0 as output.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
April 5, 2010 at 1:38 am
malleswarareddy_m (4/4/2010)
declare @bit bitset @bit='00000'
select @bit
This gives 1 as output.
This must be a typo because the result is 0.
April 5, 2010 at 5:49 am
malleswarareddy_m (4/4/2010)
Good QOD.This Question gives good information about bit datatypes.when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.
Go through the discussion over this thread to get more info about bit.
http://www.sqlservercentral.com/Forums/Topic854871-2605-1.aspx
SQL DBA.
April 5, 2010 at 8:45 am
Nice 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
April 5, 2010 at 10:16 am
malleswarareddy_m (4/4/2010)
Good QOD.This Question gives good information about bit datatypes.when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.
. . . .
This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero
DECLARE @MyNum int
SET @MyNum = ' '
-- attempt arithmetic operation
Select @myNum * 4
-- result is 0, not an error.
April 5, 2010 at 12:24 pm
john.arnott (4/5/2010)
This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero
DECLARE @MyNum int
SET @MyNum = ' '
-- attempt arithmetic operation
Select @myNum * 4
-- result is 0, not an error.
Good point, but I would like it more if SQL Server throws an exception and let developers know upfront that it's wrong to assign string/character values to an integer data type.
April 5, 2010 at 2:44 pm
It will throw an error if you attempt to assign a NON-empty string to an integer data type.
I can see your point for an empty string/character value, but it does come in handy when you need to work with data where someone has set all the columns that should be integer to text :crazy:
April 5, 2010 at 9:05 pm
vk-kirov (4/5/2010)
malleswarareddy_m (4/4/2010)
declare @bit bitset @bit='00000'
select @bit
This gives 1 as output.
This must be a typo because the result is 0.
Yes it will give zero as ouptut. Some typing mistake.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
April 5, 2010 at 9:07 pm
john.arnott (4/5/2010)
malleswarareddy_m (4/4/2010)
Good QOD.This Question gives good information about bit datatypes.when we use space or all zero it bit will convert it into zero.If we give numeric(numbers) it will convert it into one.
. . . .
This is true for other numeric datatypes as well. Spaces or empty strings are implicitly converted to zero
DECLARE @MyNum int
SET @MyNum = ' '
-- attempt arithmetic operation
Select @myNum * 4
-- result is 0, not an error.
I think it will throw error when converting it to string datatype except(TRUE/False)
Malleswarareddy
I.T.Analyst
MCITP(70-451)
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply