Dynamic select column name on the basis of a flag I have a config table where there are config values are stored as key, value pair in each row. 
 And there is another table which have two columns (lets say column1 and column2). Now I have to select column1 value in select statement if value for flag1 is present and equal to 1 in config table and select column2 if value for flag1 is absent or equal to 0.

I fetched the flag value in a variable- 

DECLARE @flag smallint 
SELECT @flag = CASE WHEN EXISTS (SELECT 1 
                                 FROM   dbo.ACCOUNT_CONFIG WITH (nolock) 
                                 WHERE acct_id = #{accountId} 
                                 AND key_name = 'flag1' AND key_value = 1) THEN 1 
                                 ELSE 0 END


Now I have to do some thing like:

SELECT col1, col2 
From   ACCOUNT_USER table 
where  acct_id = #{accountId} 
AND    CASE @flag1 = 1 THEN column1 = #{COLUMN_VALUE} 
       ELSE column2=#{COLUMN_VALUE} END


But above statement is not working for me.
If your final query returns 2 columns, it returns 2 columns. You can move CASE to the SELECT sentence but it will return 2 columns.

SELECT CASE WHEN @flag1 = 1 THEN #{COLUMN_VALUE} END AS col1, 
       CASE WHEN @flag1 &lt;&gt; 1 THEN #{COLUMN_VALUE} END AS col2 
FROM   ACCOUNT_USER table 
WHERE  acct_id = #{accountId};


In case you need only one column named as COL1 or COL2 I'd suggest to use a dynamic query.