2017-05-04 7 views
0

私はテキスト管理用のアプリケーションを開発中です。さまざまな言語の短いテキストがたくさんあります。テキストは、幅(px)と行数を指定してテキスト領域に収める必要があります。目的は、使用可能な線幅を使用しないすべてのテキストを特定の超過分で見つけて、編集のためにそれらをユーザーに示すことです。
例: enter image description here 左側のテキストでは、各行には使用可能な領域の4分の1しかかかりません。右側のテキストは大丈夫です。他の値に応じて値を見つけるためのSQLクエリ

私は左の例については、このよう

id, idText, lineorder, usedspace, availablespace 
3 87  1   111  430 
4 87  2   116  430 
5 87  3   171  430 
6 87  4   120  430 

を見て、右例えば、次のようになり、このテーブルlengthcheckresultあります

id, idText, lineorder, usedspace, availablespace 
3 87  1   408  430 
4 87  2   120  430 
5 87  3   0  430 
6 87  4   0  430 

だから私はすべてのテキストを検索しますSQLクエリを必要とします後に行が続く場合は、利用可能な領域のx%未満を占める行があります。これが可能だと思いますか?私はどのように始めるのか分かりません。

答えて

1

使用この(テーブル名などについての仮定を作る)

select 
    A.id 
--, (anything else you want) 
from dbname.dbo.tblname A 
where usedspace > 0 
    and availablespace > 0 -- Avoid divide by zero 
    and usedspace/availablespace < 0.5 -- Assume less than 50%? Pick your value. 
    and A.idText = 1234 -- The text of interest 
    and exists 
    (select B.id from dbname.dbo.tblname B 
    where B.idText = A.idText  -- Part of same text 
     and B.lineorder > A.lineorder -- Only later lines 
     and B.usedspace > 0   -- Only non-empty lines 
) 
-- order by etc, as required. 

これはまた、そのテキストを以下している任意の割合(この場合は50%)よりも短いテキストのあなたの作品を見つけたようなもの空ではありません。

+0

これは素晴らしい作品です。ありがとうございます! – ondrums

関連する問題