MSSQL ENDOFMONTH Replacement

Workaround procedure for ENDOFMONTH-Funktion (DAX) - DAX | Microsoft Learn

CREATE VIRTUAL PROCEDURE views.endofmonth( IN getdate date ) returns (outdate date) asBEGIN     DECLARE date monthlater =  timestampadd( SQL_TSI_MONTH, 1, getdate );    select  timestampadd( SQL_TSI_DAY, - dayofmonth(monthlater), monthlater); END;;

 

Usage Examples

call views.endofmonth( cast ( '2012-02-07' as date ) ) result: 2012-02-29 call endofmonth( current_date ) result: Last day of current month using in WHERE clause SELECT foo from table.bar WHERE column = ( call endofmonth( current_date ) )

1 Like