如何在括号内使用#temp?
或者如何在括号内使用表变量?
显然,真正的查询要复杂得多。
失败:
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
CREATE TABLE #Temp (sID int NOT NULL);
select count(*)
from
(
insert into #Temp
select top 10 sID from [docSVsys]
select * from #temp
) as [count]
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
失败:
select count(*)
from
(
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
CREATE TABLE #Temp (sID int NOT NULL);
insert into #Temp
select top 10 sID from [docSVsys]
select * from #temp
) as [count]
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
作品:
但我需要在括号内使用#temp
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp
CREATE TABLE #Temp (sID int NOT NULL);
insert into #Temp
select top 10 sID from [docSVsys]
select * from #temp
IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp