字符串函数从上一期或回车开始得到正确的 1000

问题描述 投票:0回答:1

我的问题是在另一个线程下提出和回答的问题的后续问题。但是,没有问的问题是如何提取前 1000 个或最接近的“。”之后的剩余字符。 :

https://dba.stackexchange.com/questions/121206/string-function-to-get-left-1000-but-only-to-last-period-or-carriage-return/324359?noredirect=1#评论632652_324359

我正在尝试编写此查询的反面(如下所示),这将允许我将数据从报表生成器报表的一个部分流向另一个部分。下面的查询(由 Solomon Rutzky 编写)提取前 1000 个字符或最接近的“.”。它完美地工作。

LEFT(LEFT(@Text, 1000),
 1001 - CHARINDEX('.', REVERSE(LEFT(@Text, 1000)))) 

我目前拥有的是:

declare @Text varchar(max) = '*Up unpacked friendly ecstatic so possible humoured do. Ample ended might folly quiet one set spoke her. We no am former valley assure. Four need spot ye said we find mile. Are commanded him convinced dashwoods did estimable forfeited. Shy celebrated met sentiments she reasonably but. Proposal its disposed eat advanced marriage sociable. Drawings led greatest add subjects endeavor gay remember. Principles one yet assistance you met impossible. The who arrival end how fertile enabled. Brother she add yet see minuter natural smiling article painted. Themselves at dispatched interested insensible am be prosperous reasonably it. She boisterous use friendship she dissimilar considered expression. Sex quick arose mrs lived. Mr things do plenty others an vanity myself waited to. Always parish tastes at as mr father dining at. Led ask possible mistress relation elegance eat likewise debating.

Or am nothing amongst chiefly address. The its enable direct men depend highly. Ham windows sixteen who inquiry fortune demands.

Is be upon sang fond must shew. Really boy law county she unable her sister. Feet you off its like like six. Among sex are leave law built now. In built table in an rapid blush. Merits behind on afraid or warmly. In either so spring wished. Melancholy wayBy message*';

with cte as (
    Select
        LEN(@Text) C,
        LEN(@Text) - 1000 Var,
        LEFT(LEFT(@Text, 1000), 1001 - CHARINDEX('.', REVERSE(LEFT(@Text, 1000)))) Narrative,
        RIGHT(Substring(@Text, 1000, 296), CHARINDEX('.', LEFT(@Text, 296))) Cntd,
        @Text Text
)
Select
    *,
    RIGHT(RIGHT(@Text, 1000), Var - CharIndex('.', Right(@Text, + Var))) Continued
from CTE

我为

LEN
确定了
@Text
,它是 1296。然后我创建了
Var
来让我看到剩余文本的
LEN
是什么。

'Narrative' 给了我前 1000 个或最接近的 '.'它工作得很好。它提供了一个完整的句子The its enable direct men dependent highly.第二段第二行

Continued中,我尝试在1000个字符的末尾或最近的(.)处占用。有什么建议么?提前谢谢你。

sql sql-server reportbuilder
1个回答
0
投票

当我使用查询:LEFT(LEFT(@Text, 1000), 1001 - CHARINDEX('.', REVERSE(LEFT(@Text, 1000)))) 叙述,针对声明语句中的段落,它允许我提取前 1000 个字符或最近的句点。

使用这个,提取的文本的最后一行是“它使直接的人高度依赖。”

我想弄清楚的是如何创建另一个查询,该查询将占用 1000 个字符或句点停止的位置,并从下一行开始,即“Ham windows 16 who inquiry fortune demands”。并将一直持续到文末。

到目前为止,在我的努力中,我已经设法让它从下一段开始,下一段以“是在……”开头。

我晚上应该在家,并将继续努力。然而,任何建议将不胜感激。

我在 SQL 2019 上。

© www.soinside.com 2019 - 2024. All rights reserved.