我有一个rdlc报告,显示从Microsoft SQL 2008数据库中的单个文本字段检索到的转录信息。该报告很简单,它包含一个短标题和一个包含单个文本框的正文。我们遇到的问题是一些报告数据被切断了。没有错误信息被切断。经过一些测试后,我们确定文本框中断了大约32,000个字符。在这个发现后我做了一些研究,我发现唯一有用的是对msdn的引用social.msdn 我们遇到的一些转录包含500,000个字符,我们无法知道它是否会上升。有什么方法可以解决报告的文本框32,000个字符限制吗?
答案 0 :(得分:1)
我提出的解决方案是编写一些T-SQL来分解大块文本 分成小块,然后返回一个包含每30,000个char文本块的行的表。然后在报告上将我的文本框放在列表中。 下面是SQL
declare @transcriptionBody TABLE
(
SegmentNumber int identity(1,1),
BodyPart nvarchar(max)
)
declare
@bodyPart varchar(max),
@body nvarchar(max),
@indexToLastNewLineInBodyPart int,
@lenOfBody int,
@MAX_CHARACTERS int,
@numberOfCharactersLeftInString int,
@position int
set @MAX_CHARACTERS = 30000
set @indexToLastNewLineInBodyPart = 0
set @numberOfCharactersLeftInString = 0
set @position = 0
/*
* Get the long string of characters from your database. In this example the
* [Body] field is a text field.
*/
select @body = Body from [Transcription] with(nolock) where Id = @TranscriptionId
set @lenOfBody = len(@body)
/*
* Loop through the @body variable chopping up the string into managable chuncks
* and inserting those chuncks into a table variable called @transcriptionBody.
* The loop exists when the
*/
while (@position < @lenOfBody)
begin
/*
* If the transcription body is less than 30,000 then insert it into
* our table variable and return.
*/
if (@lenOfBody <= @MAX_CHARACTERS and @position = 0)
begin
insert into @transcriptionBody(BodyPart) values(@body)
set @position = @lenOfBody
end
/*
* Otherwise we need do the following
* 1. Get the number of chars in the string starting from the input start index.
* 2. If the number of chars in the string is > than the max allowable chars then
* substring off the first 30,000 chars into a body part.
*
* 2a. Now have a string consisting of 30,000 chars but you have no idea where it
* cut off (it could be in the middle of a word). So you now need to get the
* index of the last newline and re-break the string on that.Then insert it
* into the table variable and set the position.
*
* 3. If the number of chars in the string IS NOT > than the max allowable chars
* then substring off the remaining chars into a body part and insert it into our
* table variable
*/
else
begin
-- 1.
select @numberOfCharactersLeftInString = (@position - @lenOfBody) * -1
-- 2.
if (@numberOfCharactersLeftInString > @MAX_CHARACTERS)
begin
select @bodyPart = substring(@body, @position, @MAX_CHARACTERS)
-- 2a.
select @indexToLastNewLineInBodyPart = Len(@bodyPart) - charindex(char(13)+char(10),reverse(@bodyPart))
if (@indexToLastNewLineInBodyPart > 0)
begin
select @bodyPart = substring(@bodyPart,@position,@indexToLastNewLineInBodyPart)
insert into @transcriptionBody(BodyPart) values(@bodyPart)
select @position = @position + len(@bodyPart)
end
end
else
begin
select @bodyPart = substring(@body, @position, @numberOfCharactersLeftInString)
insert into @transcriptionBody(BodyPart) values(@bodyPart)
select @position = @position + len(@bodyPart)
end
end
end
select * from @transcriptionBody order by SegmentNumber