问题
What SQL functions are available in NetSuite saved searches (formulas)?
回答1:
The following is a list of SQL functions (shown as example code) available to use in NetSuite saved searches as of September 2019. These saved searches do not allow all SQL functions so it is helpful to know what is available to work with.
If you have a NetSuite account with access to SuiteAnswers you can follow this link to Answer Id: 10101.
It took me a while to find this since it didn't show up in web searches. I want to make it easy to find. Enjoy!
Numeric Functions
ExamplesABS( {amount} )
ACOS( 0.35 )
ASIN( 1 )
ATAN( 0.2 )
ATAN2( 0.2, 0.3 )
BITAND( 5, 3 )
CEIL( {today}-{createddate} )
COS( 0.35 )
COSH( -3.15 )
EXP( {rate} )
FLOOR( {today}-{createddate} )
LN( 20 )
LOG( 10, 20 )
MOD( 3:56 pm-{lastmessagedate},7 )
NANVL( {itemisbn13}, '' )
POWER( {custcoldaystoship},-.196 )
REMAINDER( {transaction.totalamount}, {transaction.amountpaid} )
ROUND( ( {today}-{startdate} ), 0 )
SIGN( {quantity} )
SIN( 5.2 )
SINH( 3 )
SQRT( POWER( {taxamount}, 2 ) )
TAN( -5.2 )
TANH( 3 )
TRUNC( {amount}, 1 )
Character Functions Returning Character Values
ExamplesCHR( 13 )
CONCAT( {number},CONCAT( '_',{line} ) )
INITCAP( {customer.companyname} )
LOWER( {customer.companyname} )
LPAD( {line},3,'0' )
LTRIM( {companyname},'-' )
REGEXP_REPLACE( {name}, '^.*:', '' )
REGEXP_SUBSTR( {item},'[^:]+$' )
REPLACE( {serialnumber}, '&', ',' )
RPAD( {firstname},20 )
RTRIM( {paidtransaction.externalid},'-Invoice' )
SOUNDEX( {companyname} )
SUBSTR( {transaction.salesrep},1,3 )
TRANSLATE( {expensecategory}, ' ', '+' )
TRIM ( BOTH ',' FROM {custrecord_assetcost} )
UPPER( {unit} )
Character Functions Returning Number Values
ExamplesASCII( {taxitem} )
INSTR( {messages.message}, 'cspdr3' )
LENGTH( {name} )
REGEXP_INSTR ( {item.unitstype}, '\d' )
TO_NUMBER( {quantity} )
Datetime Functions
ExamplesADD_MONTHS( {today},-1 )
LAST_DAY( {today} )
MONTHS_BETWEEN( SYSDATE,{createddate} )
NEXT_DAY( {today},'SATURDAY' )
ROUND( TO_DATE( '12/31/2014', 'mm/dd/yyyy' )-{datecreated} )
TO_CHAR( {date}, 'hh24' )
TO_DATE( '31.12.2011', 'DD.MM.YYYY' )
TRUNC( {today},'YYYY' )
Also see Sysdate in one of the example sections below.
NULL-Related Functions
ExamplesCOALESCE( {quantitycommitted}, 0 )
NULLIF( {price}, 0 )
NVL( {quantity},'0' )
NVL2( {location}, 1, 2 )
Decode
ExamplesDECODE( {systemnotes.name}, {assigned},'T','F' )
Sysdate
ExamplesTO_DATE( SYSDATE, 'DD.MM.YYYY' )
or
TO_CHAR( SYSDATE, 'mm/dd/yyyy' )
See also TO_DATE and TO_CHAR in the Datetime Functions.
Case
ExamplesCASE {state}
WHEN 'NY' THEN 'New York'
WHEN 'CA' THEN 'California'
ELSE {state}
END
or
CASE
WHEN {quantityavailable} > 19 THEN 'In Stock'
WHEN {quantityavailable} > 1 THEN 'Limited Availability'
WHEN {quantityavailable} = 1 THEN 'The Last Piece'
WHEN {quantityavailable} IS NULL THEN 'Discontinued'
ELSE 'Out of Stock'
END
Analytic and Aggregate Functions
ExamplesDENSE_RANK ( {amount} WITHIN GROUP ( ORDER BY {AMOUNT} ) )
or
DENSE_RANK( ) OVER ( PARTITION BY {name}ORDER BY {trandate} DESC )
KEEP( DENSE_RANK LAST ORDER BY {internalid} )
RANK( ) OVER ( PARTITION by {tranid} ORDER BY {line} DESC )
or
RANK ( {amount} WITHIN GROUP ( ORDER BY {amount} ) )
来源:https://stackoverflow.com/questions/39131715/what-sql-functions-are-available-in-netsuite-saved-searches