2

我有一个要提取的列,但遇到了问题!该列存储为 ntext 类型并包含一个 RTF 文档,因此看起来像这样:

{\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl  {\f0\fnil\fcharset0\fprq2 Arial;}  {\f1\fswiss\fcharset0\fprq2 Arial;}  {\f2\froman\fcharset2\fprq2 Symbol;}}  {\colortbl;\red0\green0\blue0;\red255\green255\blue255;}  {\stylesheet{\s0\itap0\nowidctlpar\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}}  {\*\generator TX_RTF32 15.0.530.502;}  \deftab1134\paperw11909\paperh16834\margl1138\margt1138\margr1138\margb1138\widowctrl\formshade\sectd  \headery720\footery720\pgwsxn11909\pghsxn16834\marglsxn1134\margtsxn1134\margrsxn1134\margbsxn1134\pard\itap0\nowidctlpar\plain\f1\fs20 Stephan Bos  28/11/2011 11:19:55\par\par Sold in guy. He likes him, feedback this afternoon.\par Will send him the CV and also our terms.\par Made him aware of our fees.\par }

但我希望将其提取回(rtf 或 txt,我并不介意)我尝试使用 BCP,它已成功提取文档,但它们最终与列完全相同,但在每个字符而不是我所期望的(上面的例子最终会读到类似的内容:

Stephan Bos  28/11/2011 11:19:55
Sold in guy. He likes him, feedback this afternoon.
Will send him the CV and also our terms.
Made him aware of our fees.

我正在使用(正在提取)的 BCP 提取如下:

set nocount on;
Declare @sql varchar(1000);
declare @noteid int;
declare xx1 cursor for select nic.NotebookItemId from NotebookItemContent nic
inner join NotebookLinks nl on nl.NotebookItemId = nic.NotebookItemId
inner join NotebookItems ni on ni.NotebookItemId = nic.NotebookItemId
where nl.clientid = 1235074
AND ni.NotebookTypeId = 56;
open xx1;
fetch xx1 into @noteid;
while (@@fetch_status = 0)
begin
set @sql = 'BCP "SELECT memo FROM Monarch_Pronet_ITOIL.dbo.notebookitemcontent where notebookitemid=' + cast(@noteid as varchar) + 
'" QUERYOUT \\bhamws475\docs\' + cast(@noteid as varchar) + '.rtf -T -f \\bhamws475\docs\bcp.fmt -S ' + @@SERVERNAME
EXEC master.dbo.xp_CmdShell @sql
fetch xx1 into @noteid;
end;
close xx1;
deallocate xx1;

谁能指出我正确的方向?

4

1 回答 1

1

我想我现在明白了 - 问题是 BCP 保存的 RTF 不被 Word 识别为 RTF 文件 - 它作为纯文本文件打开。

这是因为导出的文件是 Unicode 格式(您可以看到,屏幕截图中每个字符后面都有一个空格)。

解决方案是告诉 bcp 不要以 Unicode 格式保存 - 我认为这可以通过-c开关或在格式文件中指定所需的字符集来完成。

于 2012-04-18T07:37:10.017 回答