请帮忙。我创建了一个存储过程,其中不必传递任何值。喜欢: 创建过程UpdateTableMonthlyTrend
在其中我已经声明了一些变量,并从一些表中存储了值。喜欢:
@PreviousMonth , @CurrentYear
现在我将这些值传递给我之前创建的另一个StoredProcedure,接受这些变量'值。喜欢
Create procedure TableMonthlyTrend (@previousMonth Varchar(20), @CurrentYear int)
从第一个程序开始,我将值传递给第二个过程,如:
exec TableMonthlyTrend @previousMonth, @CurrentYear.
但是在执行第一个过程时,没有任何内容传递给第二个过程。就像我一样 exec UpdateTableMonthlyTrend - 没有任何反应,第二个程序运行但它无法运行它。
请帮忙,让我知道我在做什么错误。
这是第一个SP: -
ALTER PROCEDURE [dbo].[BO_sp_Update_SupportKPI_MonthlyTrend]
AS BEGIN
BEGIN TRANSACTION;
BEGIN TRY
CREATE TABLE #Temp_CurrentDateTime
(Id INT IDENTITY(1,1),
CurrentDate DATETIME,
CurrentMonth VARCHAR(15),
PreviousMonth VARCHAR (15),
CurrentYear VARCHAR(10)
)
INSERT INTO #Temp_CurrentDateTime VALUES (GETDATE(),MONTH(GETDATE()),MONTH(DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0)),YEAR (GETDATE()))
UPDATE #Temp_CurrentDateTime
SET PreviousMonth = CASE
WHEN PreviousMonth = 1 THEN 'January'
WHEN PreviousMonth = 2 THEN 'February'
WHEN PreviousMonth = 3 THEN 'March'
WHEN PreviousMonth = 4 THEN 'April'
WHEN PreviousMonth = 5 THEN 'May'
WHEN PreviousMonth = 6 THEN 'June'
WHEN PreviousMonth = 7 THEN 'July'
WHEN PreviousMonth = 8 THEN 'August'
WHEN PreviousMonth = 9 THEN 'September'
WHEN PreviousMonth = 10 THEN 'October'
WHEN PreviousMonth = 11 THEN 'November'
WHEN PreviousMonth = 12 THEN 'December'
ELSE PreviousMonth
END
WHERE Id = 1
DECLARE
@PreviousMonth VARCHAR(50)
SET @PreviousMonth = (SELECT PreviousMonth from #Temp_CurrentDateTime WHERE Id = 1)
DECLARE
@CurrentYear INT
SET @CurrentYear = (SELECT CurrentYear FROM #Temp_CurrentDateTime )
DECLARE
@YearFromTable INT
SET @YearFromTable = (SELECT TOP 1 Year FROM BO_SupportKPI_MonthlyTrend_New ORDER BY Year desc)
IF @PreviousMonth = 'December'
BEGIN
SET @CurrentYear = @YearFromTable
IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 9)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth,@CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 10)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth,@CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 11)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth,@CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 12)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 13)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 14)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 15)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 16)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 17)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 18)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 19)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 20)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
END
ELSE
BEGIN
SET @PreviousMonth = @PreviousMonth
SET @CurrentYear = @CurrentYear
IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 9)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 10)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 11)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 12)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 13)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 14)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 15)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 16)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 17)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 18)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 19)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
ELSE IF @PreviousMonth = (SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'BO_SupportKPI_MonthlyTrend_New' and ORDINAL_POSITION = 20)
BEGIN
EXEC BO_sp_SupportKPI_MonthlyTrend @PreviousMonth, @CurrentYear
END
END
END
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
END CATCH;
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
END
GO