if @GOODS='是' select * into #BB where PRD_NO='123' else select * into #BB where PRD_NO='456'
这样的SQL语句提示#BB已存在....
但我一定要根据变量@GOODS的不同而插入不同的数据到#BB...请问该情况该如何解决呢?
这样的SQL语句提示#BB已存在....
但我一定要根据变量@GOODS的不同而插入不同的数据到#BB...请问该情况该如何解决呢?
drop table #BB
goif @GOODS='是' select * into #BB where PRD_NO='123' else select * into #BB where PRD_NO='456'
if object_id('tempdb.dbo.#BB') is not null drop table #BB
go
if @GOODS='是'
begin
select * into #BB from prdt where PRD_NO='123'
end else
begin
if object_id('temp..#BB') is not null
begin
drop table #BB
select * into #BB from prdt where PRD_NO='456'
end还是一样的提示 数据库中已存在名为 '#BB' 的对象。
declare @GOODS varchar(500)
if @GOODS='是'
begin
select * into #BB1 from prdt where PRD_NO='123'
end else
begin
select * into #BB2 from prdt where PRD_NO='456'
end select * into #BB from prdt where 1 = 0
insert into #BB select * from #BB1
insert into #BB select * from #BB2sql server 会默认检查你创建的表是否存在之类,这个算是bug吧,一定要不同名字才可以的
你的from 字段呢,
如果是有意漏掉的
那前面就可以
不过如果和你的业务不一样
前面的代码也是不对的
最好 insert into #BB select
或者把所有代码贴出来
declare @GOODS varchar(500)
if object_id('temp..#BB') is not null
begin
drop table #BB
end
if @GOODS='是'
begin
select * into #BB from prdt where PRD_NO='123'
end
else
begin
select * into #BB from prdt where PRD_NO='456'
end