ease20022002
Technical User
Hi, I am trying to write a stored procedure that has an input parameter. That input parameter will determine which INSERT script I want to run in the stored procedure.
The problem I am having is I can't seem to figure out how to wrap the Insert Statements in the Case statements without getting errors. I always get an error where it says there is an error near CASE and END with the syntax below. Also, I've tried the Case statement with and without the ELSE in there and it still doesn't work. Here is what I have:
Any help would be greatly appreciated.
Thanks
The problem I am having is I can't seem to figure out how to wrap the Insert Statements in the Case statements without getting errors. I always get an error where it says there is an error near CASE and END with the syntax below. Also, I've tried the Case statement with and without the ELSE in there and it still doesn't work. Here is what I have:
Code:
CREATE PROCEDURE spInsertActivities (
-- Add the parameters for the stored procedure here
@ImportTable Varchar(20) --Variable to indicate from which Import Table the Insert is coming from
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Case
When @ImportTable = 'CognosExtract' Then
INSERT INTO [FinancialDB].[dbo].[Activities]
([Activity])
Select Activity
From CognosExtract a
Where Not Exists
(
Select Activity
From Activities b
Where b.Activity = a.Activity
)
Group By a.Activity
When @ImportTable = 'ActualsExtract'
INSERT INTO [FinancialDB].[dbo].[Activities]
([Activity])
Select Activity
From ActualsExtract a
Where Not Exists
(
Select Activity
From Activities b
Where b.Activity = a.Activity
)
Group By a.Activity
End
END
GO
Any help would be greatly appreciated.
Thanks