两步即可完成
第一步. 创建cmmData.xml文件,并存入到能与sql服务器共享的文件夹中(如:\\10.252.21.6\sharedfolder)
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--This node is used for SSIS to locate records in bulk files, the sequences and ids of the fields here should exactly the same with data's physical position in files.-->
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="100"/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="50"/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="100"/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="50"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="ref" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="2" NAME="JO" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="3" NAME="PN" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="4" NAME="Creteria" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="5" NAME="DA" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="6" NAME="Result" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="7" NAME="Program" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="8" NAME="Eployee" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="9" NAME="TransDate" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="10" NAME="Descr" xsi:type="SQLNVARCHAR" />
</ROW>
</BCPFORMAT>
第二步:写查询
SELECT 'cmm1',a.Jo,a.PN,a.Creteria,a.Result,a.Program,'auto',a.TransDate,a.Descr
FROM OPENROWSET(BULK N'\\10.252.21.6\Shared folder for temp data exchange only\CMM DATA ANALYSIS\RESULT FILES\CMM1data.csv',
Formatfile=N'\\10.252.21.6\cmm data analysis\TEMP\fmt_cmmData.xml',FIRSTROW=2) as a