Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««123

TSQL Expand / Collapse
Author
Message
Posted Wednesday, April 07, 2010 7:00 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 5:42 AM
Points: 3,189, Visits: 4,146
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
Post #898457
Posted Wednesday, April 07, 2010 7:02 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Wednesday, May 08, 2013 10:33 AM
Points: 10,989, Visits: 10,529
vk-kirov (4/7/2010)
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

Wow he is fast
Good of him to front up, admit a mistake and apologise, rather than just replacing his post with NA.
Oh...

NA




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #898459
Posted Wednesday, April 07, 2010 7:06 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 4:31 AM
Points: 12, Visits: 69
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
Post #898463
Posted Wednesday, April 07, 2010 7:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Wednesday, May 08, 2013 10:33 AM
Points: 10,989, Visits: 10,529
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

all cool




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #898465
Posted Wednesday, April 07, 2010 12:18 PM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491, Visits: 3,008
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

Post #898878
Posted Tuesday, March 06, 2012 3:55 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 9:43 AM
Points: 469, Visits: 193
Good and straight forward question.

Thanks
Post #1262596
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse