ALTER PROCEDURE [dbo].[Timesheet_update]
AS
BEGIN
DECLARE @sql2 nvarchar(max), @status nvarchar(1)
SET @sql2 = 'insert into s21022020 (s21_stfno) select m_stfno from master where m_status<>'D''
EXECUTE (@sql2)
END
EXECUTE Timesheet_update
导致错误:
Msg 207,第16层,状态1,第23行无效的列名“ D”。
m_status列包含数据= D
我不明白您为什么觉得有必要使它成为动态SQL-只需将语句直接写在存储过程中-像这样:
ALTER PROCEDURE [dbo].[Timesheet_update]
AS
BEGIN
INSERT INTO s21022020 (s21_stfno)
SELECT m_stfno
FROM master
WHERE m_status <> 'D'
END