title: Use SQL Declare values in a Case Statement. Operands and Integer values will come from a database table
body: <p>I have a SQL table that stores value inserted by management. I am trying to used the operand values in a Select statement. Management can set values of null, =, &gt;= or &lt;= in the table.</p>
  <p>--Get values for LifeCycle D</p>
  <pre><code>DECLARE @LowerCYSaleValD Int
  DECLARE @UpperCYSaleValD Int
  DECLARE @LowerOperandValD VARCHAR(50)
  DECLARE @UpperOperandValD VARCHAR(50)
  </code></pre>
  <p>Values being set:</p>
  <pre><code>SET @LowerCYSaleValD = (SELECT LowerCYSaleVal FROM #LifeCycleFormulas WHERE  LifeCycleAssigned = 'D') 
  SET @UpperCYSaleValD = (SELECT UpperCYSaleVal FROM #LifeCycleFormulas WHERE  LifeCycleAssigned = 'D') 
  SET @LowerOperandValD = (SELECT LowerOperandVal FROM #LifeCycleFormulas WHERE  LifeCycleAssigned = 'D') 
  SET @UpperOperandValD  = (SELECT UpperOperandVal FROM #LifeCycleFormulas WHERE  LifeCycleAssigned = 'D')
  </code></pre>
  <p>Values returned:</p>
  <pre><code>@LowerCYSaleValD  = 50
  @UpperCYSaleValD  =  149
  @LowerOperandValD  =  &gt;=
  @UpperOperandValD  =  &lt;=
  </code></pre>
  <p>In my case statement this works:</p>
  <pre><code>WHEN h.Sales &gt;= 50 AND h.sales &lt;=149 THEN 'D'
  </code></pre>
  <p>This works:</p>
  <pre><code>WHEN h.Sales &gt;= @LowerCYSaleValD AND &lt;= @UpperCYSaleValD THEN 'D'
  </code></pre>
  <p>I need to convert this to:</p>
  <pre><code>WHEN h.Sales @LowerOperandValD @LowerCYSaleValD AND @UpperOperandValD @UpperCYSaleValD THEN 'D' 
  </code></pre>