TSQL整理
http://www.cnblogs.com/ghd258/archive/2006/03/20/354147.html
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER procedure usp_ImportMultipleFiles @filepath varchar(500),
@pattern varchar(100), @TableName varchar(128)
as
set quoted_identifier off
declare @query varchar(1000)
declare @max1 int
declare @count1 int
Declare @filename varchar(100)
set @count1 =0
create table #x (name varchar(200))
set @query ='master.dbo.xp_cmdshell "dir '+@filepath+@pattern +' /b"'
insert #x exec (@query)
delete from #x where name is NULL
select identity(int,1,1) as ID, name into #y from #x
drop table #x
set @max1 = (select max(ID) from #y)
--print @max1
--print @count1
While @count1 <= @max1
begin
set @count1=@count1+1
set @filename = (select name from #y where [id] = @count1)
set @Query ='BULK INSERT '+ @Tablename + ' FROM "'+ @Filepath+@Filename+'"
WITH ( FIELDTERMINATOR = '','',ROWTERMINATOR = ''n'')'
--print @query
exec (@query)
insert into logtable (query) select @query
end
drop table #y
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/93029/viewspace-1023500/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- tsql的奇特語法SQL
- Dbml檔案提取建表TSql-CodeSmithSQLMIT
- DBA工具——DMV——如何知道TSQL語句已執行了多久SQL
- java刷題整理--異常整理Java
- js 整理JS
- webpack整理Web
- MacVIM 整理Mac
- 面試整理面試
- 待整理
- Maven 整理Maven
- 面試整理-Java綜合高階篇(吐血整理)面試Java
- 幫你整理 Java 中常見設計模式整理Java設計模式
- Linux整理Linux
- 思路整理篇
- Vue整理(1.0.0)Vue
- PHP面試整理PHP面試
- vue面試整理Vue面試
- event loop整理OOP
- MySQL 部分整理MySql
- AutoreleasePool分析整理
- Nmap指令整理
- 變數整理變數
- GIt操作整理Git
- babel 配置整理Babel
- git命令整理Git
- Git 命令整理Git
- oracle注入整理Oracle
- js iframe 整理JS
- iOS 推送整理iOS
- php $_server 整理PHPServer
- sql 使用整理SQL
- css hack 整理CSS
- redis 命令整理Redis
- oracle 碎片整理Oracle
- RMAN命令整理
- 效率工具整理
- 面試題整理面試題
- 待整理 mybatisMyBatis