**I have a problem with a query, my table looks something like [this](https://i.stack.imgur.com/He2ZJ.png).**

*As a result of the query I want the beginning of the month of the current day knowing that if it is January begins 01/01/2017. We start from the last days of the month, we know that the beginning of the month is the end of the previous month plus one.
My query is as follows:*

```
select * 
from (select top 11 case when replace(convert(varchar, EndMonth, 111), '/','-') = replace(convert(varchar, getdate(), 111), '/','-') then replace(convert(varchar, EndMonth, 111), '/','-') else replace(convert(varchar, DATEADD(day,1,EndMonth), 111), '/','-') end as inicio  
from EndMonths 
where EndMonth >= convert(date,getdate()) 
and Year between  DATEPART (year, getdate()) 
and ( (DATEPART (year, getdate())+1)) or id = (select top 1 id-1 from P_materials.dbo.dia_cierre_fiscal where Year= DATEPART (year, getdate()) and Month(EndMonth) = Month(getdate()) order by EndMonth desc) 
order by EndMonth)a 
union 
select case when GETDATE()<=(select EndMonth from EndMonths where Year=2017 and NameMonth='Jenuary') then convert(varchar,YEAR(GETDATE()))+'-01-01' else '' end

```

*it was running before it was February once it was February it did not give me the same result.*