IF (EXISTS(Select * from sys.sysprocedure where LCase(proc_name) = LCase('DOM')))
THEN Drop procedure DOM
END IF

GO

create function DBA.DOM( in @mnth integer,in @yr integer,in @Return30 smallint default 0 ) 
returns integer
begin
  if @Return30 = 0 then
    if @mnth in( 1,3,5,7,8,10,12 ) then return(31)
    else
      if @mnth in( 4,6,9,11 ) then return(30)
      else
        if((MOD(@yr,4) = 0) and(MOD(@yr,100) <> 0)) OR (MOD(@yr,400) = 0) then //and(MOD(@yr,400) = 0)
          return(29)
        else
          return(28)
        end if
      end if
    end if
  else return(30)
  end if
end