Good Morning All,
as i am new to the SP, may any one please help me what is the possible error in my USP.
Whenever i tried to execute the above SP, sometime it gives correct result, but sometimes its showing error as table dbo.surface_mount_MONTHLY is already exists
and some times it is working fine for surface_mount but for solder its not inserting any record but stating Command executed successfully.
CREATE PROCEDURE [extract_data_surface_mount_solder]
(
@Action VARCHAR(10)
)
AS
BEGIN
IF (@Action = 'surface_mount')
BEGIN
DROP TABLE [dbo].[surface_mount_MONTHLY]
SELECT Year, Month, MANAGER_CODE, GROUP, SUM(sales) AS Sales, SUM(AverageProfit) AS AverageCostBasedProfit, SUM(CostProfit) AS CostProfit
INTO dbo.surface_mount_MONTHLY
FROM dbo.surface_mount
GROUP BY Year, Month, MANAGER_CODE, GROUP
END
ELSE IF (@Action = 'solder')
BEGIN
DROP TABLE [dbo].[solder_MONTHLY]
SELECT SELECT Year, Month, MANAGER_CODE, GROUP, SUM(saales) AS Sales, SUM(AverageProfit) AS AverageCostBasedProfit, SUM(CostProfit) AS CostProfit
INTO dbo.solder_MONTHLY
FROM dbo.solder
GROUP BY Year, Month, MANAGER_CODE, GROUP
END
END
using sql-server-2014 and 2008
Thank You