Ask Your Database in Plain English: Text-to-SQL for Finance and Sales Teams
By Shaghil Shahzad, Easify AI · · 6 min read
Most finance and sales teams have the same queue. Someone needs a number that isn't on any dashboard, such as last quarter's revenue from repeat customers in Germany, and the request goes to the one person who can write SQL. The answer arrives in two days, by which time the meeting has passed.
Text-to-SQL is a way to shorten that queue. You type the question in plain English and get the answer from the database directly. It works well when it is set up carefully, and it gives confident wrong answers when it isn't. This post covers both.
What text-to-SQL is
Your company data almost certainly sits in a relational database: orders, invoices, customers, products. The language for asking those databases questions is SQL. Text-to-SQL tools use a language model to translate an ordinary question into SQL, run it and show you the result.
The model needs to know your database structure (which tables exist, what the columns mean, how tables connect) to write a sensible query. The better that context, the better the answers.
Example questions
Here is the kind of question a sales or finance team might ask, and the SQL a tool could generate for it.
"How many new customers did we sign each month this year?"
SELECT DATE_TRUNC('month', created_at) AS month,
COUNT(*) AS new_customers
FROM customers
WHERE created_at >= '2026-01-01'
GROUP BY month
ORDER BY month;
"What were our top ten customers by invoiced amount last quarter?"
SELECT c.name,
SUM(i.amount_net) AS invoiced
FROM invoices i
JOIN customers c ON c.id = i.customer_id
WHERE i.invoice_date >= '2026-07-01'
AND i.invoice_date < '2026-10-01'
GROUP BY c.name
ORDER BY invoiced DESC
LIMIT 10;
Both look simple, and both hide decisions. Is "new customer" the date the account was created, or the date of the first order? Is "invoiced amount" net or gross, and does it subtract credit notes? A person would ask. A tool that doesn't know will pick one.
Where it goes wrong
| Problem | What happens | Example |
|---|---|---|
| Ambiguous definitions | The tool picks a meaning nobody agreed on | "Revenue" read as gross invoices, when finance means net of credit notes |
| Joins | Rows are duplicated or dropped | Joining orders to order lines and summing the order total once per line |
| Dates and time zones | Periods are shifted or cut short | Timestamps stored in UTC, so late-evening orders land in the wrong day or month |
| Fiscal calendars | "Last quarter" means calendar, not your financial year | A company with an April year-end gets the wrong quarter |
| Permissions | People see data they shouldn't | A sales rep asking about all reps' commission |
Watch out: the dangerous errors are not the queries that fail. They are the ones that run, return a plausible number, and are wrong. A total inflated by a duplicated join looks perfectly normal.
Definitions are the biggest issue. Most businesses have several versions of "revenue", "active customer" or "churn", and the right one depends on who is asking. If those definitions only live in people's heads, no tool can apply them consistently.
Joins are the classic technical trap. Summing a value from one table after joining to a table with more rows per record inflates the result.
Dates catch everyone. A timestamp stored in UTC, reported to a team in the UK or central Europe, puts some evening transactions into the next day, and at month end into the next month.
How to make it reliable
None of this means text-to-SQL can't be trusted. It means the setup matters more than the model.
- Agree your metric definitions and write them down. This is often called a semantic layer: a single place that says exactly how revenue, margin, active customer and the rest are calculated. The tool uses those definitions instead of guessing.
- Describe the tables and columns. Plain descriptions such as "amount_net is excluding VAT, in EUR" make a large difference to query quality.
- Connect with read-only access. Give the tool a database user that can only read, and only the tables it needs. A mistaken query should never be able to change or delete data.
- Show the SQL with every answer. Anyone who wants to check can, and analysts can spot a wrong join in seconds.
- Use row-level security for sensitive data. Let the database decide who sees which rows, so a sales rep only sees their own accounts whichever question they ask.
- Log every question and query. Keep a record of who asked what, the SQL that ran and when. It is your audit trail, and the best source of improvements to your definitions.
- Test against known reports. Before rollout, ask questions whose answers you already know from your finance reports, and compare.
Note: PostgreSQL and SQL Server both have built-in row-level security. PostgreSQL uses policies created with CREATE POLICY once row security is enabled on a table; SQL Server, since 2016, uses security policies with predicate functions. Either way the rule is enforced by the database, not by the chat tool.
Tip: start with the questions your analyst gets asked most often. Write the agreed definitions for those first. That covers most of the real demand without trying to document the whole database on day one.
What a safe setup looks like
- TriggerQuestion asked
Typed in plain English
- AISQL generated
Using agreed metric definitions

- StepQuery runs
Read-only user, row-level security
PostgreSQL
- YouYou check the answer
SQL shown beside the result
- ResultAnswer and log
Number or chart, query recorded
Excel
The human step matters most for figures that leave the team: board packs, forecasts and anything sent to a client or auditor. For a quick internal question, glancing at the SQL is often enough.
When a dashboard is still better
Text-to-SQL is good for one-off questions. It is not a replacement for business intelligence.
| Use a dashboard when | Use text-to-SQL when |
|---|---|
| The same numbers are reviewed every week | The question is new or occasional |
| Many people need to see exactly the same figure | One person needs an answer now |
| The metric is formally reported (board, lenders, auditors) | You are exploring before deciding what to report |
| Trends over time matter more than a single value | You want to drill into one specific case |
A good pattern is to use text-to-SQL to explore, and promote the questions people ask repeatedly into proper dashboard metrics.
Choosing a tool
Look for the safeguards above, not just a demo that answers a clean question on a tidy database. Ask whether it supports your database, whether it shows the SQL, how it stores your metric definitions, and where your data goes during a query.
Our own product, Easify Data AI, works with PostgreSQL, MySQL and SQL Server, with connections to Shopify, Google Analytics and Power BI. Whichever tool you consider, the checklist is the same.
If data protection is a concern, our guide to a GDPR-safe RAG pipeline on European servers covers similar questions about where data is processed, and AI security risks in European businesses covers access control more broadly.
Summary
- Text-to-SQL turns plain-English questions into database queries, so finance and sales get answers without the analyst queue.
- It fails quietly on vague definitions, joins, dates and time zones, and permissions.
- Reliability comes from setup: agreed metric definitions, read-only access, visible SQL, row-level security and logging.
- Check important figures before they leave the team, using the SQL shown with the answer.
- Keep dashboards for the numbers everyone watches; use text-to-SQL for everything else.
Frequently asked questions
- What is text-to-SQL?
- Text-to-SQL is software, usually built on a large language model, that turns a question written in everyday language into an SQL query, runs it against your database and returns the result as a number, table or chart.
- Can text-to-SQL change or delete data?
- It shouldn't be able to. Connect it with a read-only database user, so that even a badly generated query can only read data, never change it.
- How do I know the answer is right?
- Check that the tool shows the SQL it ran, uses your agreed metric definitions, and gives the same result as a known report for a few test questions. For important figures, have someone who knows the data read the query before the number goes into a board pack.
- Does text-to-SQL replace our BI dashboards?
- No. Dashboards are better for fixed numbers that many people watch regularly. Text-to-SQL is better for the one-off questions that never make it onto a dashboard.
