April 6, 2010 at 12:49 am
good question, thanks 🙂
April 6, 2010 at 10:28 am
malleswarareddy_m (4/5/2010)
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)
Sorry?? What will cause an error?
Your statement looks to be reversed of what you may have meant -- aren't we talking about converting from strings to numerics? My example of implicit conversion from a string to an int does not cause an error, nor would an empty string, the point being that it's not just conversions to the bit type where empty or blank strings result in zero.
I didn't find a BOL or MSDN article on this specific behavior, but from what I did find, it seems clear that the SQL engine sets the target to zero, then adds the numeric evaluation of the string, ignoring spaces. With nothing else to evaluate, the result remains zero.
You say you "think it will throw error". Did you try it?
April 6, 2010 at 9:58 pm
john.arnott (4/6/2010)
malleswarareddy_m (4/5/2010)
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)
Sorry?? What will cause an error?
Your statement looks to be reversed of what you may have meant -- aren't we talking about converting from strings to numerics? My example of implicit conversion from a string to an int does not cause an error, nor would an empty string, the point being that it's not just conversions to the bit type where empty or blank strings result in zero.
I didn't find a BOL or MSDN article on this specific behavior, but from what I did find, it seems clear that the SQL engine sets the target to zero, then adds the numeric evaluation of the string, ignoring spaces. With nothing else to evaluate, the result remains zero.
You say you "think it will throw error". Did you try it?
your Example is correct.when convert the bit into string it will thrown an error.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
April 7, 2010 at 6:36 am
NA
April 7, 2010 at 6:41 am
vivek.yadav (4/7/2010)
vk-kirov,You are worng...
declare @bit bit
set @bit='00000'
select @bit
will always return 0 as o/p.
Please if you can check again.
That's what he said. Your post claimed it returned 1. Read back and check. 😛
He did say it was probably just a typo.
Oh, and you spelt 'wrong' wrong - another typo? 😉 😛
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 7, 2010 at 7:00 am
Paul White NZ
Posted Today @ 4:41:28 PM
... 1 second to read the post and make editing ...
Edited: Today @ 4:41:29 PM by vivek.yadav
Amazing reaction time :w00t:
April 7, 2010 at 7:02 am
vk-kirov (4/7/2010)
Paul White NZPosted Today @ 4:41:28 PM
... 1 second to read the post and make editing ...
Edited: Today @ 4:41:29 PM by vivek.yadav
Amazing reaction time :w00t:
Wow he is fast :laugh:
Good of him to front up, admit a mistake and apologise, rather than just replacing his post with NA.
Oh...:unsure:
NA
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 7, 2010 at 7:06 am
Hi aplogize Paul...
Actually i didn't find the nxt page.
that's why i posted that...
But you are much faster then me.. i edited in 1 sec. and you read that post in 1 sec.. 🙂
Sorry for that
April 7, 2010 at 7:07 am
vivek.yadav (4/7/2010)
Hi aplogize Paul...Actually i didn't find the nxt page.
that's why i posted that...
But you are much faster then me.. i edited in 1 sec. and you read that post in 1 sec.. 🙂
Sorry for that
:laugh: all cool :laugh:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 7, 2010 at 12:18 pm
malleswarareddy_m (4/6/2010)
john.arnott (4/6/2010)
malleswarareddy_m (4/5/2010)
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)
Sorry?? What will cause an error?
Your statement looks to be reversed of what you may have meant -- aren't we talking about converting from strings to numerics? My example of implicit conversion from a string to an int does not cause an error, nor would an empty string, the point being that it's not just conversions to the bit type where empty or blank strings result in zero.
I didn't find a BOL or MSDN article on this specific behavior, but from what I did find, it seems clear that the SQL engine sets the target to zero, then adds the numeric evaluation of the string, ignoring spaces. With nothing else to evaluate, the result remains zero.
You say you "think it will throw error". Did you try it?
your Example is correct.when convert the bit into string it will thrown an error.
What do you mean? your statement that an error will be thrown doesn't make sense to me. Please post an example of an error being created. A short script like this should make it clear.
Declare @MyChar char(10)
Declare @MyBit Bit
set @MyBit = 1234 -- BIT datatype sees as 1
set @MyChar = @myBit -- Implicitly convert 1 to '1'
select @MyBit MyBit, @MyChar MyChar -- Returns: 1 1
set @MyBit = 0 -- Reset so you can see the next step do something
select @MyBit MyBit, @MyChar MyChar -- Returns: 0 1
set @MyBit = @MyChar -- Implicitly convert '1' to 1
select @MyBit MyBit, @MyChar MyChar -- Returns: 1 1
March 6, 2012 at 3:55 pm
Good and straight forward question.
Thanks
Viewing 11 posts - 16 through 25 (of 25 total)
You must be logged in to reply to this topic. Login to reply