Shorter version without the need of scalar functions.
DECLARE @Date SMALLDATETIME = GETDATE();
SELECT CONVERT( char(8), DATEADD(MM, DATEDIFF(MM, 0, @Date), -1), 112);
More formulas: http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/