Excel Formula to SQL Converter

Paste an Excel formula and get the equivalent SQL expression or SELECT query — IF and IFS as CASE WHEN, SUMIFS and COUNTIFS as conditional aggregates, and the right string and date functions for your database.

Runs in your browserUpdated

Paste with or without the leading =. Commas and semicolons both work as argument separators.

Output

Cell references

References appear here once you enter a formula.

Give references meaningful names (B2 → price). Ranges become lists; multi-column ranges become lists of rows.

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the Excel Formula to SQL

  1. Paste an Excel or Google Sheets formula, or pick one from Examples.
  2. Choose the target language — the page starts with SQL, and you can switch at any time.
  3. Rename the detected cell references to meaningful variable names, for example B2 → price.
  4. 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

ExcelSQL
IF(c, a, b)CASE WHEN c THEN a ELSE b END
IFS / SWITCHCASE WHEN … END
AND, OR, NOTAND, OR, NOT
= and <>= and <>
a & bCONCAT(a, b)
a ^ bPOWER(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 / XLOOKUPnot translated — use a JOIN
IFERROR(x, y)COALESCE(x, y) (NULL only)
LEFT / MID / LENLEFT, 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

ExcelMySQLPostgreSQLSQL Server
LENCHAR_LENGTHLENGTHLEN
FINDLOCATEPOSITION … INCHARINDEX
REPLACEINSERTOVERLAYSTUFF
DATE(y, m, d)STR_TO_DATE(CONCAT…)MAKE_DATEDATEFROMPARTS
YEAR(d)YEAR(d)EXTRACT(YEAR FROM d)YEAR(d)
TODAY()CURRENT_DATECURRENT_DATECAST(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?
Use 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?
A conditional aggregate: 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?
Join the lookup table: 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(…), "").
Why are my references called col_a, col_b?
SQL works with columns, so each reference becomes the column of its letter. Type your real column names next to each reference to rename them.
Is my formula uploaded?
No. Everything runs in your browser.

Related tools