Does anyone know a way to do the equivalent of `RE...
# general
j
Does anyone know a way to do the equivalent of
REGEXP_COUNT
in NS (Saved Search or SuiteQL)? I need to do a search for something and sort by the number of times a certain word appears.
heh
Copy code
SELECT LENGTH(REGEXP_REPLACE(REPLACE('here is my <br/> string with lots of <br/> breaks in<br/>it','<br/>','|'), '[^|]', '')) AS numlinebreaks
🙃 1
👍🏻 1
turns out this doesn’t actually work for me. I want to count line breaks in the
description
of line items.
but I’ve tried
\n
,
<br>
,
<br />
, etc
and none seem to appear, I think NS strips those out in SuiteQL
annoying
DBeaver to the rescue
Copy code
"SELECT it.displayname, 

AVG(LENGTH(REGEXP_REPLACE(REPLACE(tl.memo,'
','|'), '[^|]', ''))) AS average_linebreak_count,

MAX(LENGTH(REGEXP_REPLACE(REPLACE(tl.memo,'
','|'), '[^|]', ''))) AS max_linebreak_count

FROM transactions tx
JOIN transaction_lines tl ON tl.transaction_id = tx.transaction_id
JOIN items it ON it.item_id = tl.item_id

WHERE 

tx.transaction_type = 'Sales Order'
AND tx.trandate > '2020-12-31'
AND tl.memo LIKE '%
%'

GROUP BY it.displayname

ORDER BY AVG(LENGTH(REGEXP_REPLACE(REPLACE(tl.memo,'
','|'), '[^|]', ''))) DESC"