用DTS导入文本文件时,怎样跳过文本文件的第一行和最后一行
来源:互联网 发布:安装php 编辑:程序博客网 时间:2024/05/18 21:43
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Supposewehaveatableasfollows:
CREATETABLE[ignore_rows](
[c1][int]NULL,
[c2][char](10)
)
Andthetextfileisasfollows:
1,aaa
2,bbb
3,ccc
100,ddd
To ignorethefirstandthelastrowofthetextfilewhen importingthetextfiletothetable,youcanusethesesteps:
1.InSQLEnterpriseManager,rightclicktheDataTransformationServices,clickNewPackage,thiswilllaunchtheDTSpackagedesigner.
2.ClickPackage-->Propertiesmenu,clicktheGlobalVariablestab,addtwoglobalvariables:
currentRow,int,initialvalue0 -->weuseittotracktherowwearecurrentlyprocessing.
lastRow,int,initialvalue0 -->weuseittorecordtherownumberofthetextfile.
3.AddanActiveXScriptTasktothedesignpane,thescriptisasfollows.
ThisscriptusetheFileSystemObject(FSO),formoreinformationregardingFSO,pleasecheckitonMSDN.
FunctionMain()
Dimfso
Dimts
DimrowCount
Setfso=CreateObject("Scripting.FileSystemObject")
Setts=fso.OpenTextFile("C:/data/ignore_rows.txt",1) '1forreading
rowCount=0
WhileNotts.AtEndOfStream
ts.SkipLine
rowCount=rowCount+1
Wend
DTSGlobalVariables("currentRow").Value=0
DTSGlobalVariables("lastRow").Value=rowcount
Main=DTSTaskExecResult_Success
EndFunction
4.Dragtwoconnectionstothepane,onetextfileconnectionandoneMicrosoftOLEDBProviderforconnection,andthendragaTransformDataTask.TheActiveXtransformationscriptisasfollows:
FunctionMain()
DTSGlobalVariables("currentRow").Value=DTSGlobalVariables("currentRow").Value+1
'Thefollowingcodewillskipandfirstrowandlastrow
ifDTSGlobalVariables("currentRow").Value=1orDTSGlobalVariables("currentRow").Value=DTSGlobalVariables("lastRow").Valuethen
Main=DTSTransformStat_SkipRow
else
DTSDestination("c1")=DTSSource("Col001")
DTSDestination("c2")=DTSSource("Col002")
Main=DTSTransformStat_OK
endif
EndFunction
5.Settheprecedencecorrectly,thefinalpackageisasfollows:
ActiveXScriptTask--(onsuccess)-->Textfileconnection--(transformdata)-->SQLconnection
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Supposewehaveatableasfollows:
CREATETABLE[ignore_rows](
[c1][int]NULL,
[c2][char](10)
)
Andthetextfileisasfollows:
1,aaa
2,bbb
3,ccc
100,ddd
To ignorethefirstandthelastrowofthetextfilewhen importingthetextfiletothetable,youcanusethesesteps:
1.InSQLEnterpriseManager,rightclicktheDataTransformationServices,clickNewPackage,thiswilllaunchtheDTSpackagedesigner.
2.ClickPackage-->Propertiesmenu,clicktheGlobalVariablestab,addtwoglobalvariables:
currentRow,int,initialvalue0 -->weuseittotracktherowwearecurrentlyprocessing.
lastRow,int,initialvalue0 -->weuseittorecordtherownumberofthetextfile.
3.AddanActiveXScriptTasktothedesignpane,thescriptisasfollows.
ThisscriptusetheFileSystemObject(FSO),formoreinformationregardingFSO,pleasecheckitonMSDN.
FunctionMain()
Dimfso
Dimts
DimrowCount
Setfso=CreateObject("Scripting.FileSystemObject")
Setts=fso.OpenTextFile("C:/data/ignore_rows.txt",1) '1forreading
rowCount=0
WhileNotts.AtEndOfStream
ts.SkipLine
rowCount=rowCount+1
Wend
DTSGlobalVariables("currentRow").Value=0
DTSGlobalVariables("lastRow").Value=rowcount
Main=DTSTaskExecResult_Success
EndFunction
4.Dragtwoconnectionstothepane,onetextfileconnectionandoneMicrosoftOLEDBProviderforconnection,andthendragaTransformDataTask.TheActiveXtransformationscriptisasfollows:
FunctionMain()
DTSGlobalVariables("currentRow").Value=DTSGlobalVariables("currentRow").Value+1
'Thefollowingcodewillskipandfirstrowandlastrow
ifDTSGlobalVariables("currentRow").Value=1orDTSGlobalVariables("currentRow").Value=DTSGlobalVariables("lastRow").Valuethen
Main=DTSTransformStat_SkipRow
else
DTSDestination("c1")=DTSSource("Col001")
DTSDestination("c2")=DTSSource("Col002")
Main=DTSTransformStat_OK
endif
EndFunction
5.Settheprecedencecorrectly,thefinalpackageisasfollows:
ActiveXScriptTask--(onsuccess)-->Textfileconnection--(transformdata)-->SQLconnection
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 用DTS导入文本文件时, 怎样跳过文本文件的第一行和最后一行
- 用DTS导入文本文件时,怎样跳过文本文件的第一行和最后一行
- 批处理提取文本文件第一行跟最后一行的方法
- 读取一个文本文件的最后一行
- Delphi读取文本文件的最后一行
- 除去文本文件每一行的空格&&提取每一行第一个和最后一个字符串
- Java 快速读取文本文件最后一行数据
- 获取DataTabl的第一行和最后一行的数据
- vi中跳到文件的第一行和最后一行
- vi中跳到文件的第一行和最后一行
- DataTable获取第一行和最后一行的数据
- vi中跳到文件的第一行和最后一行
- vi中跳到文件的第一行和最后一行
- java快速读取文本文件最后一行数据内容
- Linux下错误:文本文件每一行最后多了 ^M
- 使用批处理提取文件夹下所有文本文件最后一行
- PHP 删除文本文件的任意一行或添加一行
- 读文本文件的每一行 取每行最后一个空格后的子串
- 如何使用USE_CONCAT提示
- 经验
- 在Word中播放Flash和视频
- SQL注入天书—注入漏洞全接触
- pl/sql常用脚本
- 用DTS导入文本文件时,怎样跳过文本文件的第一行和最后一行
- 怎样查询磁盘的可用空间,数据文件及日志文件大小及利用率
- JSP的内置对象的调用函数介绍
- ldd命令替代方式
- EZMorph
- SQL的基本操作
- 在JSP页面中获取当前系统时间
- 五 一 出 游
- SQL的详细语法介绍——对于学习最基础知识一