I am using SQL Server 2012.
If I do the following to get a list of random numbers in the range [1,3], it works fine:
SELECT TOP 100 ABS(CHECKSUM(NEWID()))%3 + 1 [value_of_rand] FROM sys.objects
and I get such nice things (all between 1 and 3).
3 2 2 2 1 ....etc.
But if I then put the output of the same function with a chain random value in a CASE statement, it apparently does not produce only the values โโ1,2,3.
SELECT TOP 100 CASE (ABS(CHECKSUM(NEWID()))%3 + 1) WHEN 1 THEN 'one' WHEN 2 THEN 'two' WHEN 3 THEN 'three' ELSE 'that is strange' END [value_of_case] FROM sys.objects
It outputs:
three that is strange that is strange one two ...etc
What am I doing wrong here?
sql-server tsql
Anssssss
source share