Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1853

Re: CASE issue

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver
Subject Re: CASE issue
Date 2014-11-29 10:43 +0100
Organization Erland Sommarskog
Message-ID <XnsA3F46D04B264CYazorman@127.0.0.1> (permalink)
References (1 earlier) <XnsA3EF7E8B63B6CYazorman@127.0.0.1> <m4vlom$q0c$1@dont-email.me> <XnsA3EFF04705958Yazorman@127.0.0.1> <m513rc$8vr$1@dont-email.me> <MPG.2ee2ae00cb38741598968b@news.powerusenet.com>

Show all headers | View raw


Jim (jgeissman@socal.rr.com) writes:
> I believe RAND() is evaluated once at the beginning, while NEWID() is 
> evaluated each time. So one solution would be to evaluate the NEWID() 
> version and park the result in a variable and use the variable, or use 
> RAND() but base it on a seed that doesn't involve NEWID(), or at least 
> if it does, determine it outside of the CASE statement.
> 

I don't think that would work well, because you want a new random number
per row. You could use a column on the row as seed - but then it would 
be deterministic. Look at this.

SELECT rand(), rand(object_id) FROM sys.objects


-- 
Erland Sommarskog, Stockholm, esquel@sommarskog.se

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Find similar


Thread

CASE issue "twenty-six@b-mint.net" <twenty-six@b-mint.net> - 2014-11-24 10:22 +0000
  Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-24 11:26 +0000
    Re: CASE issue bradbury9 <ray.bradbury9@gmail.com> - 2014-11-24 04:16 -0800
      Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-24 14:28 +0000
        Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-28 22:47 +0100
          Re: CASE issue Jim <jgeissman@socal.rr.com> - 2014-11-28 17:19 -0800
    Re: CASE issue "twenty-six@b-mint.net" <twenty-six@b-mint.net> - 2014-11-24 13:32 +0000
      Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-24 14:25 +0000
        Re: CASE issue "twenty-six@b-mint.net" <twenty-six@b-mint.net> - 2014-11-24 16:06 +0000
    Re: CASE issue Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2014-11-24 17:18 +0100
      Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-24 23:37 +0100
        Re: CASE issue Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2014-11-25 06:25 +0100
          Re: CASE issue Jim <jgeissman@socal.rr.com> - 2014-11-28 16:07 -0800
            Re: CASE issue Erland Sommarskog <esquel@sommarskog.se> - 2014-11-29 10:43 +0100

csiph-web