国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

用DTS導(dǎo)入文本文件時, 怎樣跳過文本文件的第一行和最后一行

2024-07-21 02:06:26
字體:
供稿:網(wǎng)友

suppose we have a table as follows:

create table [ignore_rows] (
 [c1] [int] null ,
 [c2] [char] (10)
)

and the text file is as follows:

1,aaa
2,bbb
3,ccc
100,ddd

to ignore the first and the last row of the text file when importing the text file to the table, you can use these steps:

1. in sql enterprise manager, right click the data transformation services, click new package, this will launch the dts package designer.

2. click package --> properties menu, click the global variables tab, add two global variables:

currentrow , int, initial value 0  --> we use it to track the row we are currently processing.
lastrow, int, initial value 0         --> we use it to record the row number of the text file.

3. add an activex script task to the design pane, the script is as follows.

this script use the file system object (fso), for more information regarding fso, please check it on msdn.

function main()

dim fso
dim ts
dim rowcount

set fso = createobject("scripting.filesystemobject")
set ts = fso.opentextfile("c:/data/ignore_rows.txt", 1)  '1 for reading

rowcount = 0

while not ts.atendofstream
ts.skipline
rowcount = rowcount + 1
wend

dtsglobalvariables("currentrow").value=0
dtsglobalvariables("lastrow").value=rowcount

main = dtstaskexecresult_success

end function

4. drag two connections to the pane, one text file connection and one microsoft ole db provider for sql server connection, and then drag a transform data task. the activex transformation script is as follows:

function main()

dtsglobalvariables("currentrow").value=dtsglobalvariables("currentrow").value+1

'the following code will skip and first row and last row
if dtsglobalvariables("currentrow").value=1 or dtsglobalvariables("currentrow").value=dtsglobalvariables("lastrow").value then
 main=dtstransformstat_skiprow
else
 dtsdestination("c1") = dtssource("col001")
 dtsdestination("c2") = dtssource("col002")
 main = dtstransformstat_ok
end if

end function

5. set the precedence correctly, the final package is as follows:

activex script task --(on success)--> text file connection --(transform data)--> sql connection

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 海宁市| 湖口县| 灵璧县| 基隆市| 轮台县| 红桥区| 芒康县| 三河市| 遂平县| 县级市| 闻喜县| 鄂伦春自治旗| 芷江| 台中市| 阜康市| 永兴县| 新泰市| 拉孜县| 河池市| 搜索| 华池县| 望城县| 五原县| 五大连池市| 卢湾区| 江口县| 阿荣旗| 承德市| 大丰市| 正阳县| 西乌珠穆沁旗| 宜都市| 澄迈县| 邵东县| 小金县| 囊谦县| 新巴尔虎右旗| 江门市| 孟连| 宣武区| 五台县|