sql导入临时表

 1 CREATE alter Proc [dbo].[P_MDB_Project_Item]                  
 2 (                  
 3          
 4 @datablename varchar(200)              
 5 )                  
 6 as                  
 7 
 8 if object_id('tempdb..##test') is not null   --如果存在##test先删除
 9 begin
10   drop table ##test
11 end
12            
13 exec(' select * into ##test from '+@datablename)               
14 --DELETE ##test WHERE isnull(F2,'') = ''   -- 删除F1是空的数据
15 --delete  MDB_Project_Item where Year1 in (select F1 from ##test) and Project_ID in (select F2 from ##test)         
16      insert into MDB_Project_Item(Year1,Project_ID,Project_ITEM,Project_Des,Activity_ID,IsDel) 
17      select rtrim(F1),rtrim(F2),rtrim(F3),rtrim(F4),rtrim(F5),0 from ##test  
18      
19      if(@@ROWCOUNT <= 0)
20 
21              begin
22                  select '03'--没有符合条件的数据
23              end     
24       else 
25        begin
26          select count(1) from ##test --成功
27        end      
28 drop table ##test                
29 exec('truncate table '+@datablename)          
30 exec('drop table '+@datablename) 

 

posted @ 2015-06-16 14:05  IT人生(正)  阅读(77)  评论(0)    收藏  举报