Link to home
Start Free TrialLog in
Avatar of James Murphy
James MurphyFlag for Australia

asked on

Stored Procedure to return 2 dates

Hi Experts,

Thank you for taking the time to take a look at my question - your help is very much appreciated and is invaluable!

basically I want to create a stored procedure, that will return 2 dates.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE datereturn
	-- Add the parameters for the stored procedure here
	<@monthsback int>
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
DECLARE @firstDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()) + 1, DATEADD(MONTH, - @monthsBack, GETDATE())));
DECLARE @lastDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()), DATEADD(MONTH, - @monthsBack + 1, GETDATE())));
END
GO

Open in new window


Should I just create a temptable that writes the 2 dates to a field and then do a select * from temptable ? if that is the case could you please help with that part?
ASKER CERTIFIED SOLUTION
Avatar of James Murphy
James Murphy
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial