BCP SQL Server:如何在第一列插入双引号

时间:2014-09-09 04:36:20

标签: sql sql-server xml bcp

在BCP中,当我从表i导出数据时有数据

1","Engineering","Research and Development","2002-06-01 00:00:00.000"
2","Tool Design","Research and Development","2002-06-01 00:00:00.000"
3","Sales","Sales and Marketing","2002-06-01 00:00:00.000"

但是我想在第一列中使用双引号导出。像这样:

"1","Engineering","Research and Development","2002-06-01 00:00:00.000"
"2","Tool Design","Research and Development","2002-06-01 00:00:00.000"
"3","Sales","Sales and Marketing","2002-06-01 00:00:00.000"

这是我的格式文件:

    <?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <RECORD>
  <FIELD ID="1" xsi:type="CharTerm" TERMINATOR='\",\"' MAX_LENGTH="10"/>
  <FIELD ID="2" xsi:type="CharTerm" TERMINATOR='\",\"' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="3" xsi:type="CharTerm" TERMINATOR='\",\"' MAX_LENGTH="100" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR='\"\r\n' MAX_LENGTH="10"/>
 </RECORD>
 <ROW>
  <COLUMN SOURCE="1" NAME="DepartmentID" xsi:type="SQLSMALLINT"/>
  <COLUMN SOURCE="2" NAME="Name" xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="3" NAME="GroupName" xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="4" NAME="ModifiedDate" xsi:type="SQLDATETIME"/>
 </ROW>
</BCPFORMAT>

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助:

bcp“SELECT'\”'+ Field1,Field2,Field3,Field4 from DB.dbo.Table“queryout C:\ temp \ data.txt -t \”,\“-r \”\ r \ n - S -T -c