# SuiteQL Query Generator for NetSuite

> Source: https://netray.co/tools/suiteql-query-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in a table, columns, filter and sort and get a SuiteQL statement ready for the N/query module, the REST SuiteQL endpoint or the SuiteAnalytics Workbook.

## Category

netsuite

## Erp

NetSuite

## Audience

- NetSuite developer
- SuiteScript developer
- NetSuite administrator

## Tool

**Kind:** template

**Output:** code

**Language:** sql

**Fields:**

#### Table and alias

**Key:** table

**Type:** text

**Default:** transaction t

**Help:** Record table name followed by an alias, for example transaction t or customer c.

#### Columns (comma separated)

**Key:** columns

**Type:** textarea

**Default:** t.id, t.tranid, t.trandate, BUILTIN.DF(t.entity) AS customer, t.foreigntotal

**Help:** Wrap list or record fields in BUILTIN.DF() to return the display name instead of the internal ID.

#### WHERE condition

**Key:** where

**Type:** textarea

**Default:** t.type = 'SalesOrd' AND t.trandate >= TO_DATE('2026-01-01', 'YYYY-MM-DD')

#### ORDER BY

**Key:** order

**Type:** text

**Default:** t.trandate DESC

#### Row limit

**Key:** row_limit

**Type:** number

**Default:** 100

**Blocks:**

#### SuiteQL statement

**Body:** SELECT
  {{columns}}
FROM
  {{table}}
WHERE
  {{where}}
ORDER BY
  {{order}}
FETCH FIRST {{row_limit}} ROWS ONLY

#### Same statement as a single line for REST or a script string

**Body:** SELECT {{columns}} FROM {{table}} WHERE {{where}} ORDER BY {{order}} FETCH FIRST {{row_limit}} ROWS ONLY

#### Where to run it

**Body:** -- SuiteScript 2.x: query.runSuiteQL({ query: sql, params: [] }).asMappedResults()
-- REST: POST /services/rest/query/v1/suiteql?limit=1000 with header Prefer: transient and body { "q": "<statement>" }
-- UI: Analytics > SuiteAnalytics Workbook is not SuiteQL, use a SuiteQL console bundle or the N/query module

**Notes:** SuiteQL is Oracle-flavored SQL over the NetSuite analytics data source. Table and column names come from the Records Catalog in your account (Setup > Records Catalog, or the Analytics Browser). Available columns depend on role permissions and enabled features, so verify names in your account and sandbox before shipping a script.

## Content

**Intro:** SuiteQL lets you read NetSuite data with SQL instead of building saved searches in code. This generator assembles a clean statement from the pieces you fill in, so you can paste it into a script, a REST call or a test harness.

**Sections:**

#### How to use the generator

**Body:** Enter the table with an alias, list the columns, write the filter and pick a sort. The statement updates as you type, and a single-line copy is provided for pasting into a JavaScript string or a REST body. The default example reads sales orders from 2026 onward and shows the customer name using BUILTIN.DF. Change the type code and date to match your case, then run it in a sandbox first.

**Bullets:**

- Always alias the table and prefix columns with the alias
- Use TO_DATE with an explicit format for date filters
- Use FETCH FIRST n ROWS ONLY to cap result size while testing
- Quote string literals with single quotes

#### SuiteQL behavior worth knowing

**Body:** SuiteQL follows Oracle SQL syntax, so row limits use FETCH FIRST or ROWNUM rather than LIMIT. BUILTIN.DF returns the display value of a list or record field and BUILTIN.CF returns the value in the consolidated currency context. Transaction lines live in transactionline joined on the transaction ID, and transaction type codes such as SalesOrd, PurchOrd, CustInvc and VendBill are stored in the type column. Results from the REST endpoint are paged, with a default and a maximum page size of 1000 rows.

#### Reading the output

**Body:** Mapped results from N/query return objects keyed by column name or alias, so give every computed column an alias. When a column is a NetSuite internal ID, the value comes back as a number or string depending on the field, so compare carefully in JavaScript. For large exports, page through results with offset in REST or use the paged query API in N/query instead of one big fetch, which keeps governance usage and memory predictable.

#### Common mistakes

**Body:** Most failures come from a column name that exists in the UI but not in the analytics schema, a join to transactionline without the transaction filter, and missing BUILTIN.DF so reports show IDs. Another is assuming the query sees records the role cannot see: SuiteQL respects role permissions, and a script running as a restricted role returns fewer rows than an administrator.

**Bullets:**

- Check column names in the Records Catalog before use
- Filter transactionline by mainline or the parent transaction
- Test with the same role the script will run under
- Do not build SQL by concatenating user input, pass params instead

**Cta:** If your team writes a lot of SuiteQL for reporting questions, ERPray can answer those questions in plain language over NetSuite data, showing the query it ran and respecting NetSuite roles.

**Faq:**

#### Is SuiteQL the same as SQL?

**Answer:** It is Oracle-style SQL for reading NetSuite data. It supports select, joins, grouping and functions, but it is read-only and uses NetSuite table and column names. Writes still go through record APIs, not SuiteQL statements.

#### How do I limit rows in SuiteQL?

**Answer:** Use FETCH FIRST n ROWS ONLY at the end of the statement, or filter on ROWNUM in a subquery. LIMIT is not supported. In REST you can also pass limit and offset query parameters to page through results.

#### Why do I get IDs instead of names?

**Answer:** List and record fields return internal IDs by default. Wrap the column in BUILTIN.DF(column) to return the display value, and give it an alias so the result key is readable in your script.

#### Can SuiteQL replace saved searches?

**Answer:** For many read cases yes, especially joins and aggregates that are awkward in searches. Saved searches still have features SuiteQL lacks, such as some formula and summary behaviors, so check the result against an existing search before replacing it.

## Search terms

suiteql query generator, netsuite suiteql examples, suiteql builtin.df, netsuite sql query builder, suiteql transaction query, suiteql fetch first rows only, netsuite suiteql tutorial, suiteql sales order query

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
