All you need to do is to write
stored procedure[
^] (SP):
CREATE PROCEDURE GetDataToReport
AS
BEGIN
DECLARE @fdate DATETIME
DECLARE @pdate DATETIME
SET @pdate = GETDATE()
SET @fdate = DATEADD(month, DATEDIFF(month, 0, @pdate), 0)
SET @pdate = DATEADD(dd, -1, @pdate)
SELECT *
FROM TableName
WHERE DateField BETWEEN @fdate AND @pdate
END
For further information, please see:
Date and Time Data Types and Functions (Transact-SQL)[
^]
Return Data from a Stored Procedure[
^]