国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 黄龙县| 卓资县| 区。| 河北区| 三门县| 紫金县| 英吉沙县| 内乡县| 平昌县| 榆林市| 定襄县| 彭山县| 怀远县| 马尔康县| 瑞丽市| 武乡县| 遂宁市| 潢川县| 隆尧县| 东明县| 阜新| 金门县| 无极县| 赤壁市| 吴忠市| 日土县| 大港区| 永登县| 桐梓县| 拉萨市| 正安县| 伊川县| 涞源县| 罗田县| 青龙| 全南县| 县级市| 思茅市| 安宁市| 菏泽市| 博野县|