打开字节数据文件,将数据拆分为SQL中的列

时间:2013-05-30 11:44:38

标签: sql binary byte bcp

我需要一个可以读取包含以下内容的文件的

  

ÿ43223233ÿÌÿÿjiihç1Ý30BRÿ43223223ÿÌÿÿjiihæ1Ý30BRÿ4ÿÌÿÿjiihå1Ý30BRÿ4ÿÌÿÿjiihä1Ý30BRÿ43213-23ÿÌÿÿjiihã1Ý30BRÿ43223223ÿÌÿÿjiihâ1Ý30BRÿ40)ÿÌÿÿjiiiá1Ý30BRÿ4ÿÌÿÿjiiià1Ý30BRÿ4 $$ “#” #3ÿÌÿÿjiihß1Ý30BRÿ43223223ÿÌÿÿjiihÞ1Ý30BRÿ43223233ÿÌÿÿjiihÝ   1Ý30BRÿ4ÿÌÿÿjiihÜ1Ý30BRÿ

进入SQL Server中的单个列。所需的输出是

  

ÿ43223233ÿÌÿÿjiihç1Ý30BR
  ÿ43223223ÿÌÿÿjiihæ1Ý30BR
  ÿ43223223ÿÌÿÿjiihæ1Ý30BR
  ÿ43223223ÿÌÿÿjiihæ1Ý30BR

然后,必须将每一行转换为实际可读值的数组

这在SQL中是否可行?我从哪里开始??我已经尝试过BCP等但是我看不到它会继续下去。

然而,我创建了一个VB应用程序,完全按照我的需要执行,这是代码

Open "c:\binaryfile.dat" For Binary As #1
Open "c:\converted.npw" For Output As #2

Do While Not EOF(1)
   For j = 0 To 31
        Get #1, , InputInfo
        Write #2, InputInfo
   Next

   Write #2, Chr(10)
Loop

Close

Open "c:\converted.npw" For Input As #1
Open "c:\finishedproduct.csv" For Output As #3

Do While Not EOF(1)
    Input #1, Discrete, Spare, ExAn8, ExAn7, ExAn6, ExAn5, ExAn4, ExAn3, ExAn2, ExAn1, InAn8, InAn7, InAn6, InAn5, InAn4, InAn3, InAn2, InAn1, MsgCount, OpMessage, TimeMilliseconds, TimeSecs, TimeMins, TimeHours, TimeMonths, TimeDays, TimeYear2, TimeYear1, Serial4, Serial3, Serial2, Serial1, NewLineChar

    strSerial = Chr(Serial1) & Chr(Serial2) & Chr(Serial3) & Chr(Serial4)
    strDate = TimeDays & "/" & TimeMonths & "/" & TimeYear
    strTime = CInt(TimeHours) & ":" & CInt(TimeMins) & ":" & CInt(TimeSecs)


    If strDate <> "" And IsDate(strDate) And IsDate(strTime) Then
          Write #3, strSerial; strDate; Format(strTime, "HH:mm:ss"); OpMessage; MsgCount; InAn1; InAn2; InAn3; InAn4; InAn5; InAn6; InAn7; InAn8; ExAn1; ExAn2; ExAn3; ExAn4; ExAn5; ExAn6; ExAn7; ExAn8; Spare; Discrete
    End If    
Loop

0 个答案:

没有答案