为什么我无法在此过程中创建#表?
drop procedure TESTMD
go
CREATE PROCEDURE TESTMD
AS
declare @SQL_TXT varchar(1000)
BEGIN
SELECT @SQL_TXT ='create table #TESTMD2 (id numeric null)'
exec (@SQL_TXT)
SELECT @SQL_TXT='select * into #TESTMD2 from TESTMD1'
exec (@SQL_TXT)
select @SQL_TXT='insert into #TESTMD2 (id) values(1)'
exec (@SQL_TXT)
END
我收到了错误#TESTMD2 not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
答案 0 :(得分:1)
嗯,我不知道为什么在exec中它没有用,但这种方式有效
drop procedure TESTMD
go
CREATE PROCEDURE TESTMD
AS
BEGIN
create table #TESTMD2 (id numeric null)
select * into #TESTMD2 from TESTMD1
insert into #TESTMD2 (id) values(1)
END