2012-04-17 100 views
1

我有一列,我正在尋找提取但有問題!列存儲類型NTEXT,幷包含一個RTF文檔所以看起來是這樣的:從SQL Server 2008 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我不介意)這 我已經

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這已經在提取文件成功,但他們最終完全一樣的列,但每個字符間的空間,而不是我期望的(例如上述最終會讀一些喜歡嘗試

我正在使用的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; 

任何人都可以指向正確的方向嗎?

+0

所以問題是你沒有在你的輸出結束行(只是一個大的線)?當你導入數據時,我會說他們會迷失方向。如果你執行'選擇備忘錄'。 。 。 '在SQL查詢窗口中將輸出設置爲文本,你會看到只有一行還是多行? – MiMo 2012-04-17 12:22:13

+0

我採取了這個問題的截圖 - http://i.imgur.com/kGMYO.png這應該提供一些見解! – franglais 2012-04-17 14:15:12

+0

對不起,我不明白屏幕截圖顯示哪個問題。如果你按照上面的建議去做,你會看到多行嗎? (假設這是問題) – MiMo 2012-04-17 16:17:45

回答

1

我想我現在明白了 - 問題是由BCP保存的RTF不能被Word識別爲RTF文件 - 它以純文本文件的形式打開。

這是由於導出的文件採用Unicode(您看到每個字符後跟屏幕截圖中的空白空間)這一事實。

解決方法是告訴bcp不保存在Unicode中 - 我認爲可以通過-c開關或在格式文件中指定所需的字符集來完成。