home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 19,125 of 19,505   
   twenty-six@b-mint.net to All   
   CASE issue   
   24 Nov 14 10:22:29   
   
   Hello,   I'm trying to write a query to anonymise some data so need to   
   generate a random birth month.   
      
   I'm generating random numbers okay, but am trying to decode the month   
   with case statement:   
      
   select   
   case   cast(rand(checksum(newid()))*12 as int)+1   
   		when 1  then 'Jan'   
   		when 2  then 'Feb'   
   		when 3  then 'Mar'   
   		when 4  then 'Apr'   
   		when 5  then 'May'   
   		when 6  then 'Jun'   
   		when 7  then 'Jul'   
   		when 8  then 'Aug'   
   		when 9  then 'Sep'   
   		when 10 then 'Oct'   
   		when 11 then 'Nov'   
   		when 12 then 'Dec'   
   		when 13 then 'was 13!'   
   		when 0 then 'was 0!'   
   		else 'Unknown'   
   end   
     from sysobjects   
      
      
   When I run this query I get lots of 'Unknown'  values, but I'm not sure   
   why. If I just select distinct cast(rand(checksum(newid()))*12 as int)+1   
     I get the values 1-12 as expected.   It's not 0 or 13,  and if I put   
   an ifnull to convert null to 13 then I still don't get any 'was 13!'   
   entries.   
      
   So what am I missing?   
      
   Thanks,   
      
   Michael   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca