Hi Jeff /Johnny,
Johnny is right , but ,IMO ,newid() should give a different value on each execution. Otherwise "Select newid(),newid() " would be the same.
Jeff, If you look at the compute scalar operation in the query plan, this is what it is actually executing
(CASE WHEN abs(checksum(newid()))%(3)=(0) THEN 'Zero' ELSE CASE WHEN abs(checksum(newid()))%(3)=(1) THEN 'One' ELSE CASE WHEN abs(checksum(newid()))%(3)=(2) THEN 'Two' ELSE CASE WHEN abs(checksum(newid()))%(3)=(3) THEN 'Three' ELSE NULL END END END END
Which is obvious why you get NULLS and interesting in itself. From a more practical point of view..
case udfLongrunning() when 1 then 'x' when 2 then 'y' when ...........
Would cause the udf to execute on each test !!
commented on Aug 11 2010 2:03AM