SuiteQL Tips & Tricks

Here are a few SuiteQL-related tips and tricks that you might find helpful.

Limiting The Number of Results

When exploring a table, you might want to limit the number of rows that are returned by the query. You can do that by filtering with the RowNum function. For example, this query will return the first 10 records in the Transaction table.

SELECT
	*
FROM 
	Transaction
WHERE
	RowNum <= 10

Comments

When developing and troubleshooting a more complex query, it can sometimes help to comment out parts of the query. In this example, I'm commenting out a block of columns using /* .. */, and specific lines of the query by prefixing them with two dashes ("--").

SELECT
	Transaction.ID,
	Transaction.TranDisplayName,
	Transaction.TranDate,
	BUILTIN.DF( Transaction.Status ) AS OrderStatus
	/*
	Customer.LastName,
	Customer.FirstName,
	Customer.Email
	*/
FROM 
	Transaction
	-- INNER JOIN Entity AS Customer ON
		-- ( Customer.ID = Transaction.Entity )
WHERE
	( Transaction .Type = 'SalesOrd' )
	AND ( RowNum <= 10 )

Dates

Creating SuiteQL queries that involve dates can be a little tricky. However, there are a few functions that I've found that can help.

You can use the TO_DATE function to cast a string representation of a date to a true date value that SuiteQL can work with. For example:

SELECT 
	TranDate, 
	COUNT(*) as Count, 
	SUM(ForeignTotal) as Total 
FROM
	Transaction 
WHERE 
	( Type = 'SalesOrd' )
	AND ( TranDate > TO_DATE('2020-01-01', 'YYYY-MM-DD') )	
GROUP BY
	TranDate

Similarly, you can use the TO_CHAR function to cast a date value to a string, and format it as well. For example:

SELECT
	TranDate,
	TO_CHAR ( TranDate, 'YYYY-MM-DD HH:MI:SS' ),
	ForeignTotal
FROM
	Transaction
WHERE
	( Type = 'SalesOrd' )
	AND ( TranDate > TO_DATE( '2020-01-01', 'YYYY-MM-DD' ) )	

Note that TO_CHAR can also be helpful in cases where you're trying to get the time portion of a timestamp column.

And finally, here's an easy way to get the age, in days, of a transaction:

SELECT
	TranDate,
	TRUNC( SYSDATE ) - TranDate AS Age
FROM
	Transaction
ORDER BY
	TranDate

For more information on how to work with dates and times, check out this blog post.

"The SuiteQL Query Tool is a brilliant solution and we have done so much with it. We have over 130 subsidiaries and are using this to get trial balances out, cash extract - report to explain where the money went - that is looking through Accounts Payable to the actual details. So much info available now!"

Lisa Reed
Netsuite Business Implementation Specialist
acceler8 Inc

Be sure to check out some of the other free NetSuite solutions that I've made available.

Copyright © 2025 Tim Dietrich.