 <p>Hopefully It can help you to deal with your question as following code </p> <pre><code>Simple CASE expression: CASE input_expression WHEN when_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END </code></pre> <p><strong>Arguments</strong> </p> <pre><code>input_expression Is the expression evaluated when the simple CASE format is used. input_expression is any valid expression. WHEN when_expression Is a simple expression to which input_expression is compared when the simple CASE format is used. when_expression is any valid expression. The data types of input_expression and each when_expression must be the same or must be an implicit conversion. THEN result_expression Is the expression returned when input_expression equals when_expression evaluates to TRUE, or Boolean_expression evaluates to TRUE. result expression is any valid expression. ELSE else_result_expression Is the expression returned if no comparison operation evaluates to TRUE. If this argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL. else_result_expression is any valid expression. The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion. WHEN Boolean_expression Is the Boolean expression evaluated when using the searched CASE format. Boolean_expression is any valid Boolean expression. </code></pre> <p><strong>Examples</strong> </p> <pre><code>USE AdventureWorks2012; GO SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END, Name FROM Production.Product ORDER BY ProductNumber; GO </code></pre> <p><strong>If-else with 2 tables</strong></p> <pre><code>declare @a nvarchar(50) if 1=1 set @a='select * from table1' else set @a='select * from table2' begin execute sp_executesql @a end </code></pre>