我查詢優化
if(condition 1)
begin
(
-----
-----
select into #temp1
----
drop #temp1
)
end
if(condition 2)
begin
(
-----
-----
select into #temp1
----
drop #temp1
)
end
現在這種格式的存儲過程時,上面的存儲過程是執行它爲我的錯誤 說:
"There is already an object named '#temp1' in the database."
當我修改存儲過程像,
if(condition 1)
begin
(
-----
-----
select into #temp1
----
drop #temp1
)
end
if(condition 2)
begin
(
-----
-----
select into #temp2
----
drop #temp2
)
end
它很好用,但我想優化這個,因爲肌酸g太多的臨時表。
有人能幫助我嗎?
如果不存在,你可以不插入...',你正在使用什麼sql引擎/服務器? – RobertPitt 2010-09-15 10:29:04
我認爲條件1和條件2不相互排斥? '#temp1'和'#temp2'具有相同的結構嗎? – 2010-09-15 10:57:07
你可以確認你是否使用SQLServer,如果是,哪個版本? – 2010-09-15 14:39:50