存贮过程中有如下片段:if @a=1
select 1,1,1 into #temp
else if @a=2
select 2,2,2 into #temp
else
sleect 2,2 into #temp上述语句在运行时会报错, 说#temp已在数据库中存在, 当然我可以生成#temp进行插入操作, 但问题是这条路就行不通吗?
select 1,1,1 into #temp
else if @a=2
select 2,2,2 into #temp
else
sleect 2,2 into #temp上述语句在运行时会报错, 说#temp已在数据库中存在, 当然我可以生成#temp进行插入操作, 但问题是这条路就行不通吗?
先用if 语句判断下表是存在
存在删除表
然后
if @a=1
select 1,1,1 into #temp
else if @a=2
select 2,2,2 into #temp
else
sleect 2,2 into #temp
begin
Drop Table #Temp
end
if @a=1
select 1,1,1 into #temp
else if @a=2
select 2,2,2 into #temp
else
sleect 2,2 into #temp
解决方法是:就如你说的,先建立一个表,该表包含最多的列,
如: #temp(a1 int,a2 int,a3 int)
判断后插入数据,从第一列开始填充数据!