This is my code.
 HEADER\_ID is primary key.
 EFFECTIVE\_DATE is column name and contains unique values.

```
declare @ColumnName varchar(20)
    set @ColumnName='EFFECTIVE_DATE'
     select * into #temphdrid 
     from  EMP_HEADER a 
    where 
    EMPLOYEE_ID in ('1111','2222') and  
    HEADER_ID=(select  max(HEADER_ID) from EMP_HEADER b where 
    a.HEADER_ID=b.HEADER_ID and    @ColumnName=(select MAX(@ColumnName) from EMP_HEADER c
    where b.EMPLOYEE_ID=c.EMPLOYEE_ID and YEAR(FIN_START_DATE)=2016)
    and YEAR(FIN_START_DATE)=2016)
    and YEAR(FIN_START_DATE)=2016

```

When I am passing @ColumnName instead of EFFECTIVE\_DATE it is showing 10 rows, however it should show single row for each employee i.e. 2 in this case.

If I am directly passing EFFECTIVE\_DATE then it is working properly.

Please help as I am not able to understand what is the exact issue.