不,您不能创建重载的存储过程。一个会覆盖另一个。虽然重载功能是可能的。因此,将内部存储过程更改为其他名称,反之亦然(即外部存储过程)。这是一个模拟您的情况的示例。
--外部存储过程
USE [Test]
GO
-- exec [dbo].[USP_GetHomeData] 2012
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GetHomeData]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[USP_GetHomeData]
GO
CREATE PROCEDURE [dbo].[USP_GetHomeData]
-- Add the parameters for the stored procedure here
(
@Year INT
)
AS
BEGIN
DECLARE @startDate DATETIME='1/1/' + CAST(@Year AS VARCHAR(4)) -- mm/dd/yyyy
DECLARE @endDate DATETIME=GETDATE() -- mm/dd/yyyy
SELECT [Date] = DATEADD(Day,Number,@startDate)
FROM master..spt_values WITH(NOLOCK)
WHERE Type='P'
AND DATEADD(day,Number,@startDate) <= @endDate
exec [dbo].[USP_GetHomeData_Inner] '1/1/1900', @endDate
END
--内部存储过程
USE [Test]
GO
-- exec [dbo].[USP_GetHomeData_Inner] '1/1/1900', '11/25/2012'
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GetHomeData_Inner]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[USP_GetHomeData_Inner]
GO
CREATE PROCEDURE [dbo].[USP_GetHomeData_Inner]
-- Add the parameters for the stored procedure here
(
@startDate DATETIME
,@endDate DATETIME
)
AS
BEGIN
;WITH Calender AS
(
SELECT @startDate AS CalanderDate
UNION ALL
SELECT CalanderDate + 1 FROM Calender
WHERE CalanderDate + 1 <= @endDate
)
SELECT [Date] = CONVERT(VARCHAR(10),CalanderDate,25)
FROM Calender WITH(NOLOCK)
OPTION (MAXRECURSION 0)
END
结果(部分)如下
希望这可以帮助。