我正在尝试在我的过程中使用参数变量exec()
。
以下是程序:
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 ')
抛出错误:
Msg 102,Level 15,State 1,Line 20
' sp_CostBudgetedTabular'附近的语法不正确。Msg 102,Level 15,State 1,Line 21
' sp_CostActualTabular'附近的语法不正确。
sp_CostBudgetedTabular
和sp_CostActualTabular
是将日期作为参数
答案 0 :(得分:1)
CREATE PROCEDURE [dbo].[sp_CostBudgetedTabular]
(
@start DATETIME
)
AS BEGIN
SET NOCOUNT ON
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = '
DECLARE @tempActual TABLE ([MonthName] NVARCHAR(100), Total FLOAT)
DECLARE @tempBudgeted TABLE ([MonthName] NVARCHAR(100), Total FLOAT)
INSERT INTO @tempBudgeted
EXEC dbo.sp_CostBudgetedTabular @start
INSERT INTO @tempActual
EXEC dbo.sp_CostActualTabular @start '
EXEC sys.sp_executesql @SQL, N'@start DATETIME', @start = @start
END