== Why is this an issue?

Under the covers, Simple ``++CASE++`` expressions are evaluated as searched ``++CASE++`` expressions. That is,


----
CASE @foo
WHEN 1 THEN 'a'
WHEN 2 THEN 'b'
----

is actually evaluated as


----
CASE 
WHEN @foo = 1 THEN 'a'
WHEN @foo = 2 THEN 'b'
----

In most situations the difference is inconsequential, but when the input expression isn't fixed, for instance if ``++RAND()++`` is involved, it is likely to yield unexpected results. For that reason, it is better to evaluate the input expression once, assign it to a variable, and use the variable as the ``++CASE++``'s input expression.


This rule raises an issue when any of the following is used in a ``++CASE++`` input expression: ``++RAND++``, ``++NEWID++``, ``++CRYPT_GEN_RANDOM++``.


=== Noncompliant code example

[source,sql]
----
CASE CONVERT(SMALLINT, RAND()*@foo)  -- Noncompliant
WHEN 1 THEN 'a'
WHEN 2 THEN 'b'
----


=== Compliant solution

[source,sql]
----
DECLARE @bar SMALLINT = CONVERT(SMALLINT, RAND()*@foo) 
CASE @bar
WHEN 1 THEN 'a'
WHEN 2 THEN 'b'
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Assign this "CASE" input expression to a variable so that it's executed only once, and evaluate the variable instead.


=== Highlighting

the case input expression


endif::env-github,rspecator-view[]
