Dynamic End of Month date parameter call

to dynamically set end of month date from a preset month.  When you do a stored procedure that pulls in a year as @year and month as @month, this following set code will set the last day of the month.

declare @dayMax as varchar(2);
set @dayMax = ’29’

if @month in (1,3,5,7,8,10,12)
set @dayMax = ’31’
else if @month in (4,6,9,11)
set @dayMax = ’30’
else if @month in (2)
if (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0
set @dayMax = ’29’
else
set @dayMax = ’28’