Reputation: 197
I want to fetch data from one table and insert into another using stored procedure. Below is my code:
CREATE PROCEDURE uspInitiateSRFWorkFlow
@WFPolicyID nvarchar(50) = null
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO ProjectWorkflowAgg
SELECT * FROM WFPolicyDetails where MasterCode = @WFPolicyID ORDER BY Priority ASC;
END
GO
Error is : Msg 2809, Level 18, State 1, Line 1 The request for procedure 'WFPolicyDetails' failed because 'WFPolicyDetails' is a table object.
Upvotes: 0
Views: 2519
Reputation: 69
To fetch the data from one table and enter it to another it is best to use a trigger. To learn how to use the triggers, here is the link https://msdn.microsoft.com/en-IN/library/ms189799.aspx.
Hopefully it may help with your problem. Best of luck!!
Upvotes: 0
Reputation: 2379
It better to specify Columns in insert and select statment..
CREATE PROCEDURE uspInitiateSRFWorkFlow
@WFPolicyID nvarchar(50) = null
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO ProjectWorkflowAgg(Column1...,Column)
SELECT Column1...,Column FROM WFPolicyDetails where MasterCode = @WFPolicyID ORDER BY Priority ASC;
END
GO
Upvotes: 1