I am trying to use the parameter variable exec() in my procedure.
Here is the procedure:
CREATE PROCEDURE [dbo].[sp_CostBudgetedTabular](@start AS datetime)
AS
BEGIN
Exec('Declare @tempActual Table(MonthName nvarchar(MAX),Total float);
Declare @tempBudgeted Table(MonthName nvarchar(MAX),Total float);
insert into @tempBudgeted sp_CostBudgetedTabular @start
insert into @tempActual sp_CostActualTabular @start ')
It is throwing errors:
Msg 102, Level 15, State 1, Line 20
Incorrect syntax near 'sp_CostBudgetedTabular'.Msg 102, Level 15, State 1, Line 21
Incorrect syntax near 'sp_CostActualTabular'.
sp_CostBudgetedTabular and sp_CostActualTabular are procedures which take a date as parameter
EXECon an entirely static string? Why not just have the code directly in this procedure?