if @type='all'
select * into #a1 from table1
else
select * into #a1 from table1 where id>100这明明不会同时执行的,为什么老提示“#a1”对象已经存在?
select * into #a1 from table1
else
select * into #a1 from table1 where id>100这明明不会同时执行的,为什么老提示“#a1”对象已经存在?
解决办法是,先创建临时表 #,再在if else 里用 insert 语句向其中插入值.
if @type='all'
insert #a1 select * from table1
else
insert #a1 select * from table1 where id>100--好像SQL的机制的原因吧.
drop table #a1
go
if @type='all'
select * into #a1 from table1
else
select * into #a1 from table1 where id>100
DROP TABLE #a1
select * into #a1 from table1 AND @type='all'
UNION all
select * from table1 where id>100 AND @type<>'all'