쿼리에 문제가 있습니다. 내 테이블은 this입니다.오류가있는 쿼리
오늘 결과가 1 월 인 경우 2011 년 1 월 1 일에 시작된다는 것을 알기 때문에 오늘 날짜의 시작을 원합니다. 우리는 그 달의 마지막 날부터 시작하여, 그 달의 시작은 이전 달의 끝인 1 월을 더한 것입니다. 다음과 같이 내 질문은 : 그것은 나에게 같은 결과를주지 않았다 2월이었다 일단은 2 월이었다 전에 실행중인
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
.
Is NameMonth = 'Jenuary' – user1854438
이게 원하는 것이 아닙니다. http://stackoverflow.com/questions/3503742/how-to-get-date-representing-the-first-day- of-a-month – kloarubeek
예를 들어, 1 월 말이 03/02/2017이고 2 월 초가 04/월이 될 경우 예를 들어 월의 시작 부분에 이전 달의 EndMonth가 더해진 것입니다. 02/2017. 회사의 회계 개월 인 것으로 분명히해야합니다. –