每15秒从一台测量仪器获取以此形式组织的数据
14.08.2014 15:00:00
UP:69.8,DN:70.7,Q=87
FLOW: 229.214 l/s
VEL: 1.18915 m/s
14.08.2014 15:00:15
UP:69.9,DN:70.5,Q=81
FLOW: 233.031 l/s
VEL: 1.20896 m/s
14.08.2014 15:00:30
UP:69.9,DN:70.7,Q=84
FLOW: 233.716 l/s
VEL: 1.21251 m/s
我需要将它导入SQL Server 2008,按下表所示的形式组织,我觉得很难做到,请给我一个如何解决问题的想法。 :
Data UP DN Q FLOW VEL
---------------------------------------------------------------
14.08.2014 15:00:00 69.8 70.7 87 229.214 1.18915
14.08.2014 15:00:15 69.9 70.5 81 233.031 1.20896
14.08.2014 15:00:30 69.9 70.7 84 233.716 1.21251
答案 0 :(得分:0)
请查看http://msdn.microsoft.com/en-us/library/ms188365.aspx
如果将数据写入名为data.txt的文件,则可以使用以下内容:
IF OBJECT_ID('tempdb..#rawdata') IS NOT NULL DROP TABLE #rawdata
create table #rawdata (
field1 varchar(255)
, field2 varchar(255)
, field3 varchar(255)
, field4 varchar(255)
)
BULK INSERT #rawdata
FROM 'C:\data.txt'
WITH (
FIELDTERMINATOR = '\n'
, ROWTERMINATOR = '\n\n'
, TABLOCK
)
SELECT field1 As Data
, SUBSTRING(field2, 4,4) AS UP
, SUBSTRING(field2, 12,4) AS DN
, SUBSTRING(field2, 19,2) AS Q
, SUBSTRING(field3, 6,8) AS FLOW
, SUBSTRING(field4, 5,8) AS VEL
FROM #rawdata