B
bsense
Unregistered / Unconfirmed
GUEST, unregistred user!
select a = case cast(rand() * 2 as int ) <br> when 0 then 0 <br> when 1 then 1<br> when null then 0<br> else 0<br> end;<br>看上去 cast(rand() * 2 as int ) 只能获 0 ,1 <br> 但是 似乎 case cast 搜索的时候 会有超出的情况, 即使使用<br> null 也不行 ,所以必须使用else <br>但是使用<br><br>DECLARE @B FLOAT,@A INT<br>select @b=CAST(rand()*2 AS INT), @a=case <br>WHEN @B = 0 THEN 0<br>WHEN @B = 1 THEN 1<br>WHEN @B = 2 THEN 2<br>when @b is null then 999 END<br>PRINT @B<br>PRINT @A<br><br>确没有这个现象