SQL语句和删除临时表的有关问题
SQL语句和删除临时表的问题表T1:ABC123143524新表T2列D为A B大值,列E为新表T2中的列D与T1中C大值:DE234455
SQL语句和删除临时表的问题
表T1:
A B C
1 2 3
1 4 3
5 2 4
新表T2列D为A B大值,列E为新表T2中的列D与T1中C大值:
D E
2 3
4 4
5 5
另外问个删除临时表问题:
例如:
SQL codeif object_id('#f') >0 drop table #f --if object_id('#f') is not null drop table #f --if object_id('temp.#f') is not null drop table #f--if object_id('temp.#f') is not null begin drop table #f endselect (case when [A]>[B] then [A] else [B] end ) as [D] into #ffrom T1
除了第一次没问题,以后每次都提示#f已经存在,这个怎么能删掉啊
[解决办法]前几天也遇见同样的问题,坐等楼下解释...
[解决办法]MSSQL2005及以上版本:
create table t1
(
a int,
b int,
c int
)
insert into t1
select 1, 2, 3 union all
select 1, 4, 3 union all
select 5, 2, 4
select * from t1
;with aaa as
(
select case when a>b then a else b end as d,c
from t1
)
select d,case when d>c then d else c end as e
from aaa
--------------------------
de
23
44
55
[解决办法]LZ:
IF OBJECT_ID('tempdb..#f') IS NOT NULL
DROP TABLE #f
临时表存放在tempdb中,你OBJECT_ID的时候不加上库名在你的应用库 是不会体现效果的