CREATE FUNCTION dbo.udf_FirstDayofPreviousMonth (@pDate datetime)
RETURNS datetime
AS
BEGIN
DECLARE @dFirstDayPrefMonth AS datetime
SET @dFirstDayPrefMonth =
convert(datetime,
left(convert(varchar(8),
dateadd(MM,-1, @pDate), 112), 6) + '01', 112)
RETURN @dFirstDayPrefMonth
END
GO