【问题标题】:RTF Extract from SQL Server 2008从 SQL Server 2008 中提取的 RTF
【发布时间】:2012-04-17 11:16:58
【问题描述】:

我有一个要提取的列,但遇到了问题!该列存储为 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;

谁能指出我正确的方向?

【问题讨论】:

  • 所以问题是你的输出中没有结束行(只有一大行)?我会说当你导入数据时他们以某种方式迷路了。如果您在 SQL 查询窗口中执行 select memo from . . . 将输出设置为文本,您会看到一行还是多行?
  • 我已经截取了这个问题的截图 - i.imgur.com/kGMYO.png 这应该可以提供一些见解!
  • 抱歉,我不明白屏幕截图显示的是哪个问题。如果您尝试按照我上面的建议进行操作,您会看到多行吗? (假设这是问题所在)

标签: sql sql-server-2008 rtf bcp


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多