我有一个关于 T-SQL 动态 SP 的问题。第一个块是我的失败尝试,第二个是我的目标(非动态块)。
CREATE PROCEDURE UDP1_TRY_EQQQ
(@FACTUTABLE nvarchar(100))
AS
declare @sqlquery as nvarchar(100)
BEGIN
SET @sqlquery = 'DELETE FROM ' + @FACTUTABLE + ' WHERE ANEXO IN
(SELECT ANEXO FROM ' + @FACTUTABLE + ' A LEFT JOIN ALTAS_MOVILES B
ON A.ANEXO=B.TCNFOL WHERE B.TCNFOL IS NULL)'
EXEC sp_ExecuteSql @sqlquery
END
DELETE FROM FACTURACION_201210
WHERE ANEXO IN
(
SELECT ANEXO
FROM FACTURACION_201210 A
LEFT JOIN ALTAS_MOVILES B
ON A.ANEXO=B.TCNFOL
WHERE B.TCNFOL IS NULL
)