我想出的解決方案是編寫一些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