...
select ID1
into #tmp
from Aif (select count(*) from #tmp)=0
begin
if object_id('temp..#tmp') is not null
drop table #tmp select ID2
into #tmp
from A
end
...首先创建一个临时表#tmp,若表里没有数据,则把另外字段填入该表#tmp中,
报错提示存在#tmp,不知该怎么实现?
select ID1
into #tmp
from Aif (select count(*) from #tmp)=0
begin
if object_id('temp..#tmp') is not null
drop table #tmp select ID2
into #tmp
from A
end
...首先创建一个临时表#tmp,若表里没有数据,则把另外字段填入该表#tmp中,
报错提示存在#tmp,不知该怎么实现?
...
select identity(int 1,1), ID1
into #tmp
from Aif (select count(*) from #tmp)=0
begin
if object_id('temp..#tmp') is not null
drop table #tmp select identity(int 1,1),ID2
into #tmp
from A
end
...首先创建一个临时表#tmp,若表里没有数据,则把另外字段填入该表#tmp中,
报错提示存在#tmp,不知该怎么实现?
into #tmp
会产生新的表,肯定和原来表冲突。
into #tmp
from bb
go
if (select count(*) from #tmp)=0
begin
if object_id('tempdb..#tmp') is not null select b=identity(int,1,1),a
into #tmp
from bb
end
else
print 1
select ID1
into #tmp
from A
每次都会产生新表#tmp.可以改为这样:
insert into #tmp
select id1
from A