November 4, 2014 at 9:51 pm
Comments posted to this topic are about the item Fun with RAND()
November 5, 2014 at 1:09 am
Great question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
November 5, 2014 at 3:26 am
Smart question :-):-)
thank you Dave
rabih
rkaram
November 5, 2014 at 4:52 am
I hate myself not to read the relation correctly! 😀
November 5, 2014 at 5:04 am
Very good question. Thanks.
I almost got it wrong but I realized in time that the loop had a "<" and not "<="
---------------
Mel. 😎
November 5, 2014 at 5:05 am
SqlMel (11/5/2014)
Very good question. Thanks.I almost got it wrong but I realized in time that the loop had a "<" and not "<="
That's what got me. Need more coffee.
November 5, 2014 at 6:17 am
I think the answer is wrong, you can only have 1 row, but you can execute the select 0 to 9 times returning a single row.
November 5, 2014 at 6:32 am
Nice question, thank you.
November 5, 2014 at 7:09 am
alvertorave (11/5/2014)
I think the answer is wrong, you can only have 1 row, but you can execute the select 0 to 9 times returning a single row.
my thought exactly. i got it right, but ...
November 5, 2014 at 7:16 am
I forgot RAND() was exclusive. So we can get .99999..., which multiplies to 9.999999..... I take it then that storing a floating point number as an integer just truncates in SQL?
November 5, 2014 at 7:21 am
Nice question, Dave, and a good explanation. Thanks!
November 5, 2014 at 7:21 am
Ed Wagner (11/5/2014)
SqlMel (11/5/2014)
Very good question. Thanks.I almost got it wrong but I realized in time that the loop had a "<" and not "<="
That's what got me. Need more coffee.
Almost got me too. Thanks for the question.
November 5, 2014 at 7:22 am
Fun questions, thank you.
Be still, and know that I am God - Psalm 46:10
November 5, 2014 at 7:52 am
Interesting Question, I ran it a couple of time to see the different results...
November 5, 2014 at 8:24 am
Brian.Klinect (11/5/2014)
I forgot RAND() was exclusive. So we can get .99999..., which multiplies to 9.999999..... I take it then that storing a floating point number as an integer just truncates in SQL?
This may be one of those "it depends" SQL Server answers.
Run this code and see if your results are the same as mine.
Declare @decFloat Float = 9.99999999999999;
Declare @intTest Integer = @decFloat;
Select @decFloat As [Float], @intTest As [Integer];
-- Returns: 9.999999999999999
Set @decFloat = 9.9999999999999999999999999;
Set @intTest = @decFloat;
Select @decFloat As [Float], @intTest As [Integer];
-- Returns: 109
Set @decFloat = 9.999999999999999;
Set @intTest = @decFloat;
Select @decFloat As [Float], @intTest As [Integer];
-- Returns: 1010It appears that sometimes we get rounding and sometimes truncating.
Enjoy!
Viewing 15 posts - 1 through 15 (of 27 total)
You must be logged in to reply to this topic. Login to reply