How to use the Excel Formula to SQL
- Paste an Excel or Google Sheets formula, or pick one from Examples.
- Choose the target language — the page starts with SQL, and you can switch at any time.
- Rename the detected cell references to meaningful variable names, for example
B2→price. - Choose a full function or the bare expression, then copy or download the code. Helper functions are added automatically when a formula needs them.
From spreadsheet formulas to SQL
When a report outgrows Excel, its formulas usually become SQL: calculated columns in a SELECT, conditional totals in a dashboard query or a view in the data warehouse. SQL thinks in columns and rows rather than cells, so this converter treats each cell reference as a column of the current row and each range as a column to aggregate.
=SUMIFS(D2:D100, B2:B100, "North", C2:C100, ">=1000")
SELECT
SUM(CASE WHEN col_b = 'North' AND col_c >= 1000 THEN col_d ELSE 0 END) AS result
FROM my_table;
Rename the references to your real column names — B2:B100 → region — and the query is ready to run.
How Excel functions map to SQL
| Excel | SQL |
|---|---|
IF(c, a, b) | CASE WHEN c THEN a ELSE b END |
IFS / SWITCH | CASE WHEN … END |
AND, OR, NOT | AND, OR, NOT |
= and <> | = and <> |
a & b | CONCAT(a, b) |
a ^ b | POWER(a, b) |
SUM(A2:A10) | SUM(col_a) |
ROUND(x, 2) | ROUND(x, 2) |
MOD(a, b) | MOD(a, b) — sign differs |
SUMIFS / COUNTIF… | SUM(CASE WHEN … THEN … END) |
VLOOKUP / XLOOKUP | not translated — use a JOIN |
IFERROR(x, y) | COALESCE(x, y) (NULL only) |
LEFT / MID / LEN | LEFT, SUBSTRING, CHAR_LENGTH |
TODAY() / NOW() | CURRENT_DATE, CURRENT_TIMESTAMP |
Criteria become predicates
Excel criteria strings are compiled into SQL conditions: ">=1000" becomes col >= 1000, "<>closed" becomes col <> 'closed', and wildcards become LIKE patterns — "*@example.com" turns into LIKE '%@example.com'. This works for SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF and AVERAGEIFS.
Dialect differences
| Excel | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|
LEN | CHAR_LENGTH | LENGTH | LEN |
FIND | LOCATE | POSITION … IN | CHARINDEX |
REPLACE | INSERT | OVERLAY | STUFF |
DATE(y, m, d) | STR_TO_DATE(CONCAT…) | MAKE_DATE | DATEFROMPARTS |
YEAR(d) | YEAR(d) | EXTRACT(YEAR FROM d) | YEAR(d) |
TODAY() | CURRENT_DATE | CURRENT_DATE | CAST(GETDATE() AS DATE) |
What does not translate
Lookups (VLOOKUP, XLOOKUP, INDEX/MATCH) are joins in SQL, so they are flagged rather than guessed. IFERROR becomes COALESCE, which only replaces NULL — wrap divisors in NULLIF(x, 0) to avoid division errors. PostgreSQL and SQL Server divide integers as integers, so cast one side to DECIMAL when needed.
Supported functions: IF, IFS, SWITCH, AND, OR, NOT, XOR, IFERROR, IFNA, ISBLANK, ISNUMBER, ISTEXT, SUM, AVERAGE, MIN, MAX, COUNT, COUNTA, COUNTBLANK, PRODUCT, MEDIAN, ROUND, ROUNDUP, ROUNDDOWN, INT, TRUNC, ABS, SIGN, MOD, POWER, SQRT, EXP, LN, LOG, LOG10, PI, CEILING, FLOOR, RAND, RANDBETWEEN, SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, AVERAGEIFS, SUMPRODUCT, VLOOKUP, XLOOKUP, MATCH, INDEX, CONCAT, CONCATENATE, TEXTJOIN, LEFT, RIGHT, MID, LEN, UPPER, LOWER, PROPER, TRIM, SUBSTITUTE, REPLACE, FIND, SEARCH, REPT, VALUE, EXACT, TEXT (number formats), TODAY, NOW, DATE, YEAR, MONTH, DAY (lookups excluded). Load the sheet into a table first with CSV & Excel to SQL, and tidy the query with the SQL Formatter.
Tools that pair well with the Excel Formula to SQL
- Excel Formula to Python — Paste an Excel or Google Sheets formula and get a Python function with clean variable names, the right imports and helpers for SUMIFS, VLOOKUP and Excel-style rounding.
- Excel Formula to JavaScript — Paste a spreadsheet formula and get readable JavaScript: a function with named parameters, correct operator precedence and small helper functions for things JavaScript lacks, such as SUMIFS and VLOOKUP.
- CREATE TABLE Generator — Design a table column by column — types, primary key, NOT NULL, UNIQUE, auto-increment and defaults — and get the correct CREATE TABLE syntax for your database.
- Excel to JSON — Open an .xlsx workbook or paste cells straight from Excel or Google Sheets and get clean JSON.
Frequently asked questions
How do I write an Excel IF statement in SQL?
CASE WHEN condition THEN value ELSE other END. Nested IFs and IFS become a single CASE with several WHEN branches, which this converter produces automatically.What is the SQL equivalent of SUMIFS?
SUM(CASE WHEN region = 'North' AND total >= 1000 THEN amount ELSE 0 END). For one condition you can also use WHERE with a plain SUM.How do I do a VLOOKUP in SQL?
SELECT o.*, p.price FROM orders o LEFT JOIN products p ON p.sku = o.sku. A LEFT JOIN returns NULL when no match exists, like IFERROR(VLOOKUP(…), "").