读书人

能否给一个这样的存贮过程的例子?该如

发布时间: 2012-02-16 21:30:36 作者: rapoo

能否给一个这样的存贮过程的例子?
从来没有写过proc,能否给一个下面的例子?

1:判断临时表是否存在,有就drop table #temp
2:从一个表里面取数据到临时表如(select * into #temp ),
3:然后对临时表进行操作(如:select * form #temp)

[解决办法]
create proc proc1
as
if exists (select * from temp.dbo.sysobjects where id = object_id(N 'temp.dbo.[#temp] ') and OBJECTPROPERTY(id, N 'IsUserTable ') = 1)
drop table [#temp]


select * into #temp from ...


select * form #temp

go

读书人网 >SQL Server

热点推荐