Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netsuite SQL Expressions

I need to use Netsute SQL expressions on a custom field. There are certain criteria that the field needs to follow;

  • If the cell contains only 1 (or none) capital letters, return the first 2 characters, capitalized.

  • If the cell contains 2 (or more) capital letters, return only these.

  • Also, If the cell contains a forward slash '/' then include the
    forward slash as well.

I will give some examples;

Light Blue
Dark Navy
Yellow
BlacK/ReD
blue check
WHite/NAvy/GreY
berry

should become

LB
DN
YE
BK/RD
BL
WH/NA/GY
BE

I know this might be easier to accomplish with suite script, but I don't have access to it, so I have to try and make it work with SQL and formulas.

like image 597
Simon G Avatar asked Sep 22 '26 02:09

Simon G


1 Answers

You can try the following query:

SELECT CASE WHEN LENGTH({col}) <= LENGTH(REGEXP_REPLACE({col}, '[A-Z]', '')) + 1
            THEN UPPER(SUBSTR({col}, 1, 2))
            ELSE REGEXP_REPLACE({col}, '[^A-Z/]', '')
       END AS output
FROM yourTable

The regex pattern [^A-Z/] should match everything which is not a capital letter or forward slash. This then would be replaced with empty string, i.e. removed from the column.

like image 119
Tim Biegeleisen Avatar answered Sep 23 '26 17:09

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!