How to turn a column into a comma-separated list
Updated · 3 min read
Spreadsheets and query results give you values in a column, one per row. SQL filters, code and many web forms want the same values on one line, separated by commas. This comma separator does that conversion in both directions, adds the quotes and brackets your target needs, and cleans the list — duplicates, blank lines and stray spaces — on the way.
- Copy a column from Excel, Google Sheets, a database result or a text file, and paste it into the Column box. The list updates as you type.
- Pick a preset — SQL IN ( ), JavaScript / JSON array or Python list — or set the delimiter, quotes and brackets yourself.
- Leave Remove duplicates and Trim spaces on to clean the list, and choose a sort order if you need one.
- Click Copy and paste the result into your query, code or form. To go the other way, paste a list on the right and click Convert to column.
Example
Column input
1042
1043
O'Brien & Co
1042
Casablanca
02134SQL IN ( ) preset
(1042, 1043, 'O''Brien & Co', 'Casablanca', '02134')The duplicate 1042 is dropped, the spaces around Casablanca are trimmed, the apostrophe is escaped for SQL, and 02134 stays quoted so its leading zero survives.
Your data stays on your device. Everything runs in JavaScript inside this tab — nothing you paste is uploaded to DataSwitch Pro.
What people use it for
SQL WHERE … IN filters
Paste 300 customer IDs from a spreadsheet and get (1042, 1043, 'A-77') ready for SELECT * FROM orders WHERE customer_id IN (…). Text values are quoted and apostrophes are doubled (O''Brien), so the query does not break.
Arrays in code
The JavaScript / JSON preset produces ["red", "green", 3], which is also a valid Python list. Backslashes and double quotes inside values are escaped.
Email and CRM tools
Many “To”, “Tags” and bulk-search fields expect values separated by commas or semicolons. Remove duplicates on the way through so nobody is mailed twice.
Search operators and filters
Use a custom delimiter such as OR to build apple OR banana OR cherry for search engines, log tools or spreadsheet filters.
Common problems and fixes
The list is one long value
Your data is on one line, separated by spaces or commas, not one value per line. Set Also split input on to the separator your data uses; line breaks still split as well.
SQL error near an apostrophe
A value such as O'Brien ends a single-quoted string early. Use the Single ' (SQL) quote option — it writes 'O''Brien', the standard SQL escape.
Leading zeros disappeared
Values like 02134 are kept exactly as pasted. They are also quoted even when Leave numbers unquoted is on, because an unquoted 02134 would be read as the number 2134.
Oracle error ORA-01795
Oracle accepts at most 1,000 expressions in one IN list. Set New line every N values to 1000, then wrap each chunk in its own IN (…) joined with OR — or load the IDs into a table and join instead.
Duplicates were not removed
Check for invisible differences: trailing spaces (keep Trim spaces on) or different letter case (turn off Duplicates are case-sensitive).
Do it in a spreadsheet or in code
For a one-off list the tool above is quickest. These formulas and snippets do the same job inside Excel, a script or the database itself.
Excel 2019 / Microsoft 365 and Google Sheets
=TEXTJOIN(", ", TRUE, A2:A500)
' with quotes for SQL:
="('" & TEXTJOIN("', '", TRUE, A2:A500) & "')"Python
values = [line.strip() for line in open("ids.txt") if line.strip()]
unique = list(dict.fromkeys(values)) # dedupe, keep order
print(", ".join(unique))JavaScript
const list = [...new Set(text.split(/\r?\n/).map(s => s.trim()).filter(Boolean))];
console.log(list.join(", "));PostgreSQL / SQL Server
-- PostgreSQL
SELECT string_agg(DISTINCT id::text, ', ') FROM customers;
-- SQL Server 2017+
SELECT STRING_AGG(CAST(id AS varchar(20)), ', ') FROM customers;
Guides for this tool
How to Convert a Column to a Comma-Separated List
Excel TEXTJOIN, Google Sheets, SQL STRING_AGG and quoting values for WHERE IN.
How to Import a CSV File into a SQL Database
When you need whole rows in a table rather than a list of values.
Frequently asked questions
How do I convert a column into a comma-separated list?
Paste the column into the left box. Each line becomes one value and the comma-separated list appears on the right instantly. Choose a preset or set the delimiter and quotes, then click Copy.
How do I make a list for SQL WHERE IN?
Click the SQL IN ( ) preset. Text values are wrapped in single quotes with apostrophes doubled, numbers stay unquoted, and the list is wrapped in parentheses — for example (1042, 'O''Brien', '02134').
Can I convert a comma-separated list back into a column?
Yes. Paste the list into the right box and click Convert to column. Quoted values, brackets and SQL-style '' escapes are understood and removed.
Can I use a delimiter other than a comma?
Yes: semicolon, pipe, tab, space, new line, or any custom text such as OR or | .
Is my data uploaded?
No. The tool runs in JavaScript inside your browser tab, so customer IDs, emails and other private lists never leave your device.
Is there a limit on how many values I can paste?
There is no server limit. Tens of thousands of lines convert in well under a second on a normal computer.