我有输入行 -
001-407600 12/26/2011 04:25:43.250 12/26/2011 04:25:43.156
001-338000 12/26/2011 04:22:49.250 12/26/2011 04:22:49.156
001-51600 12/26/2011 04:10:53.234 12/26/2011 04:10:53.140
001-351900 12/26/2011 04:23:24.000 12/26/2011 04:23:23.906
我希望通过使用VB脚本将此数据分别写入列DATATABLE
jobid
date1
time1
date2
的表time2
中
请建议我怎么做。
答案 0 :(得分:1)
我不确定文本文件的格式,因此您可能需要使用FIELDTERMINATOR
和ROWTERMINATOR
,但这种方法比尝试更方便,更有效逐行。
set conn = createobject("ADODB.Connection")
connstr = "Provider=SQLNCLI;Data Source=server\instance;User ID=username;" & _
"Password=password;Initial Catalog=database_name;"
conn.open connstr
filepath = "c:\wherever\whatever.txt"
sql = "BULK INSERT dbo.DATATABLE FROM '" & filepath & "'" & _
" WITH (ROWTERMINATOR = '\r\n', FIELDTERMINATOR = ' ');"
conn.execute sql,,129
conn.close : set conn = nothing