Please help me to debug the error for below stored Procedure. Whenevere i tried to execute the sp i am getting error as
请帮我调试以下存储过程的错误。 Whenevere我试图执行sp我正在收到错误
(142 row(s) affected) Msg 2714, Level 16, State 6, Line 16 There is already an object named 'AOP_Monthly_GrowthRate_Acquisition' in the database.
(142行受影响)消息2714,级别16,状态6,行16数据库中已存在名为“AOP_Monthly_GrowthRate_Acquisition”的对象。
if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME =
'AOP_Monthly_GrowthRate_Acquisition' AND TABLE_SCHEMA = 'dbo')
drop table BudgetWorld_temp.dbo.AOP_Monthly_GrowthRate_Acquisition
GO
SELECT dbo.LTM_ACQUISITION_MONTHLY.Year,
dbo.LTM_ACQUISITION_MONTHLY.Month,
dbo.LTM_ACQUISITION_MONTHLY.SALES_MANAGER_CODE,
dbo.LTM_ACQUISITION_MONTHLY.SALES_GROUP,
dbo.LTM_ACQUISITION_MONTHLY.NetProductSales,
dbo.LTM_ACQUISITION_MONTHLY.AverageCostBasedProfit,
dbo.LTM_ACQUISITION_MONTHLY.ReplacementCostBasedProfit,
isnull(dbo.[Provided 2016 AOP Values_Acquisition].[AOP Sales],0) as 'AOP Sales',
isnull(dbo.[Provided 2016 AOP Values_Acquisition].[AOP
Profit Based On Average Cost],0) as 'AOP Profit Based On Average Cost'
INTO #TEMP3
FROM dbo.LTM_ACQUISITION_MONTHLY LEFT OUTER JOIN
dbo.[Provided 2016 AOP Values_Acquisition] ON
dbo.LTM_ACQUISITION_MONTHLY.Month = dbo.[Provided 2016 AOP
Values_Acquisition].Month AND
dbo.LTM_ACQUISITION_MONTHLY.SALES_MANAGER_CODE =
dbo.[Provided 2016 AOP Values_Acquisition].[Sales Manager] AND
dbo.LTM_ACQUISITION_MONTHLY.SALES_GROUP = dbo.
[Provided 2016 AOP Values_Acquisition].[Sales Group]
SELECT *,
SALES_GROWTH = CASE
WHEN ([NetProductSales] + [AOP Sales]) = 0 THEN 0
WHEN ([AOP Sales] ) > 0 AND ([NetProductSales]) = 0 THEN 1
ELSE
(([AOP Sales] -[NetProductSales])/[NetProductSales]) END
,
Margin_Growth =
CASE
WHEN ([AverageCostBasedProfit] + [AOP Profit Based On Average Cost]) = 0
THEN 0
WHEN ([AOP Profit Based On Average Cost] ) > 0 AND
([AverageCostBasedProfit]) = 0 THEN 1
else
(([AOP Profit Based On Average Cost] -
[AverageCostBasedProfit])/[AverageCostBasedProfit]) END
INTO AOP_Monthly_GrowthRate_Acquisition
FROM #TEMP3
DROP TABLE #TEMP3
Thanks a ton
万分感谢
3 个解决方案
#1
1
USE BudgetWorld_temp
GO
IF OBJECT_ID('dbo.AOP_Monthly_GrowthRate_Acquisition', 'U') IS NOT NULL
DROP TABLE dbo.AOP_Monthly_GrowthRate_Acquisition
GO
IF OBJECT_ID('tempdb.dbo.#TEMP3') IS NOT NULL
DROP TABLE #TEMP3
GO
SELECT
a.[Year],
a.[Month],
a.SALES_MANAGER_CODE,
a.SALES_GROUP,
a.NetProductSales,
a.AverageCostBasedProfit,
a.ReplacementCostBasedProfit,
ISNULL(b.[AOP Sales], 0) AS [AOP Sales],
ISNULL(b.[AOP Profit Based On Average Cost], 0) AS [AOP Profit Based On Average Cost]
INTO #TEMP3
FROM dbo.LTM_ACQUISITION_MONTHLY a
LEFT JOIN dbo.[Provided 2016 AOP Values_Acquisition] b ON a.[Month] = b.[Month]
AND a.SALES_MANAGER_CODE = b.[Sales Manager]
AND a.SALES_GROUP = b.[Sales Group]
SELECT *
, SALES_GROWTH =
CASE
WHEN [NetProductSales] + [AOP Sales] = 0 THEN 0
WHEN [AOP Sales] > 0 AND [NetProductSales] = 0 THEN 1
ELSE (([AOP Sales] -[NetProductSales])/[NetProductSales])
END
, Margin_Growth =
CASE
WHEN ([AverageCostBasedProfit] + [AOP Profit Based On Average Cost]) = 0 THEN 0
WHEN ([AOP Profit Based On Average Cost] ) > 0 AND ([AverageCostBasedProfit]) = 0 THEN 1
ELSE (([AOP Profit Based On Average Cost] - [AverageCostBasedProfit])/[AverageCostBasedProfit])
END
INTO dbo.AOP_Monthly_GrowthRate_Acquisition
FROM #TEMP3
IF OBJECT_ID('tempdb.dbo.#TEMP3') IS NOT NULL
DROP TABLE #TEMP3
#2
0
SELECT FROM INTO
从INTO中选择
Creates a table, which it cannot do if it already exits (perhaps from a previous execution).
创建一个表,如果它已经退出,则无法执行(可能来自之前的执行)。
You could swap to a temp table (prefix table name with #). Or you could use INSERT INTO instead. With the second method you may need to clear the table before populating.
您可以交换到临时表(前缀表名称带#)。或者您可以使用INSERT INTO代替。使用第二种方法,您可能需要在填充之前清除表。
#3
0
Maybe you have different default schema for your user. Try to put schema name here
也许您的用户有不同的默认架构。尝试将架构名称放在此处
INTO **dbo**.AOP_Monthly_GrowthRate_Acquisition
#1
1
USE BudgetWorld_temp
GO
IF OBJECT_ID('dbo.AOP_Monthly_GrowthRate_Acquisition', 'U') IS NOT NULL
DROP TABLE dbo.AOP_Monthly_GrowthRate_Acquisition
GO
IF OBJECT_ID('tempdb.dbo.#TEMP3') IS NOT NULL
DROP TABLE #TEMP3
GO
SELECT
a.[Year],
a.[Month],
a.SALES_MANAGER_CODE,
a.SALES_GROUP,
a.NetProductSales,
a.AverageCostBasedProfit,
a.ReplacementCostBasedProfit,
ISNULL(b.[AOP Sales], 0) AS [AOP Sales],
ISNULL(b.[AOP Profit Based On Average Cost], 0) AS [AOP Profit Based On Average Cost]
INTO #TEMP3
FROM dbo.LTM_ACQUISITION_MONTHLY a
LEFT JOIN dbo.[Provided 2016 AOP Values_Acquisition] b ON a.[Month] = b.[Month]
AND a.SALES_MANAGER_CODE = b.[Sales Manager]
AND a.SALES_GROUP = b.[Sales Group]
SELECT *
, SALES_GROWTH =
CASE
WHEN [NetProductSales] + [AOP Sales] = 0 THEN 0
WHEN [AOP Sales] > 0 AND [NetProductSales] = 0 THEN 1
ELSE (([AOP Sales] -[NetProductSales])/[NetProductSales])
END
, Margin_Growth =
CASE
WHEN ([AverageCostBasedProfit] + [AOP Profit Based On Average Cost]) = 0 THEN 0
WHEN ([AOP Profit Based On Average Cost] ) > 0 AND ([AverageCostBasedProfit]) = 0 THEN 1
ELSE (([AOP Profit Based On Average Cost] - [AverageCostBasedProfit])/[AverageCostBasedProfit])
END
INTO dbo.AOP_Monthly_GrowthRate_Acquisition
FROM #TEMP3
IF OBJECT_ID('tempdb.dbo.#TEMP3') IS NOT NULL
DROP TABLE #TEMP3
#2
0
SELECT FROM INTO
从INTO中选择
Creates a table, which it cannot do if it already exits (perhaps from a previous execution).
创建一个表,如果它已经退出,则无法执行(可能来自之前的执行)。
You could swap to a temp table (prefix table name with #). Or you could use INSERT INTO instead. With the second method you may need to clear the table before populating.
您可以交换到临时表(前缀表名称带#)。或者您可以使用INSERT INTO代替。使用第二种方法,您可能需要在填充之前清除表。
#3
0
Maybe you have different default schema for your user. Try to put schema name here
也许您的用户有不同的默认架构。尝试将架构名称放在此处
INTO **dbo**.AOP_Monthly_GrowthRate_Acquisition