2014-08-19

TSQL - User defined function that converts a date into an integer with the format YYYYMM (PeriodID)

/*

       -- Execution
       select dbo.getPeriodID( '1/31/2012' );
       select dbo.getPeriodID( cast('1/31/2012' as date) );


*/
ALTER function [dbo].[getPeriodID](
       @PeriodDate date
)
returns int
as
begin

       return(
              ( year( @PeriodDate ) * 100 )
              + month( @PeriodDate )
       );

end
;



No comments:

Post a Comment