0
이 코드는 Microsoft SQL Server Management Studio 2008에서 SQL 쿼리로 실행할 때 작동하지만 작업 단계로 설정된 경우 두 번째 조건 (월말이 아닐 때 업데이트) 만 작동합니다. 이 코드의 문제점은 무엇입니까?작업 단계 작업을 만드는 방법
--set next invoice date
declare @data nvarchar(10) --invoice date
set @data = CONVERT (date, GETDATE());
update table
set invoice_date = case when day(DATEADD(day,1,@data)) = 1 then --is last day of month
(SELECT convert(date,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)))) -- set inovice date as last day of next month
else --is not last day of month
(select DATEADD(MM,1,@data)) --add one month to inovice date
end
where status = 'current' and invoice_date = @data -- only for current inovices
언제 SQL 작업을 실행합니까? –
매일 23:00:00에 일자리가 생깁니다. – mahnamahna
(날짜, DATEADD (s, -1, DATEADD (mm, DATEDIFF (m, 0, GETDATE()) + 1,0))))) -) 다음 날짜의 마지막 날짜로 inovice 날짜를 설정합니다. 이 코드에서 다음 달 마지막 날처럼 언급했습니다. 그러나 그것이 그 달의 마지막 날을 잡았다. –