I'm trying to find the most elegant means of defaulting a column's value to the 1st of next month. The best I've been able to come up with is this:
ALTER TABLE Foo ADD
Bar datetimeoffset(0) NOT NULL DEFAULT(DATEFROMPARTS(DATEPART(year, DATEADD(month, 1, GETDATE())), DATEPART(month, DATEADD(month, 1, GETDATE())), 1))
Whilst this works, it feels really clunky because I need to calculate DATEADD(month, 1, GETDATE())
twice and because I need to do the DATEFROMPARTS
dance.
Is there a simpler way to achieve my goal?
DATEFROMPARTS(YEAR(GETDATE())+(MONTH(GETDATE())/12), 1+(MONTH(GETDATE())%12), 1)