Select Columns using Case When based on condition - SQL Server
<p>I want to select a column based on Case when based on a condition. It was working fine but I don't know how to return the proper alias Name for the selected Column.</p>

<p>For example.</p>

<pre><code>If I=1 then
I should select "L.id" with ColumnAlias as LeadId 
else 
I should select "sl.id" with ColumnAlias as ServiceLeadId
</code></pre>

<p>My output should contain only one column with proper alias like the below.</p>

<pre><code>If I=1

LeadId 
1
2
3
...
...

If I&lt;&gt;1

ServiceleadId
1001
1002
1003
...
...
</code></pre>

<p>I tried like the below</p>

<pre><code>select
CASE WHEN @i = 1 Then
                  L.Id AS LeadId
                 Else

                  sl.id AS ServiceLeadId
end
from table
</code></pre>

<p>but I got an error.</p>

<p>Please suggest me any ideas to achieve this.</p>