Home Text Tools Math & Numbers Developer Tools Date & Time Image Tools Blog
Add Prefix / Suffix to Lines

Turn a List of IDs Into an SQL IN Clause or JavaScript Array

Wrap each line in quotes and add commas to build IN (...) clauses and array literals from spreadsheet columns in seconds.

You have 300 customer IDs in a spreadsheet column and a query that needs them as a quoted, comma separated list. Typing quotes and commas by hand is slow and error-prone. Adding a prefix and suffix to every line does it in one step.

Add Prefix / Suffix to Lines FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool

The pattern

Each line becomes an item when you add a prefix and a suffix. For SQL string values, use a single quote as the prefix and a single quote plus comma as the suffix, so ABC123 becomes 'ABC123',. Numeric IDs need no quotes, only the comma. For a JavaScript array of strings, use a double quote as prefix and a double quote plus comma as suffix.

Step by step

  1. Copy the column from your spreadsheet. Each cell lands on its own line when pasted.
  2. Paste it into the Add Prefix / Suffix to Lines tool.
  3. Set the prefix to ' and the suffix to ', for text IDs, or just a comma for numbers.
  4. Copy the result and paste it between the parentheses of WHERE id IN ( ... ).
  5. Delete the final trailing comma, which would cause a syntax error.

An example

Starting with three lines, A100, B200 and C300, the result is 'A100', 'B200' and 'C300' each on its own line with commas. Your query then reads SELECT * FROM orders WHERE order_ref IN ('A100','B200','C300'). For JavaScript, wrap the whole block in square brackets and the same lines become an array literal ready to paste into a file.

Watch out for

  • The trailing comma on the last line, which breaks SQL and older JavaScript parsers.
  • Hidden spaces and blank lines in the pasted column, which create empty items.
  • Apostrophes inside values, such as O'Brien, which must be escaped by doubling them in SQL.
  • Very long IN lists, since some databases limit how many values or how large a statement can be.
  • Duplicates in the list, which are harmless for IN but may signal a data problem.

Other quick wins

The same trick builds many formats. Add a tab as the prefix to indent code, add <li> and </li> to create HTML list items, or add a hash to turn names into hashtags. For CSV, a comma suffix joins items, and for markdown bullets a dash and space prefix does the job. Think of it as a tiny templating tool for any list of plain lines.

If you plan to rerun a query regularly, consider a temporary table or a join with an uploaded list instead of a huge IN clause. For one-off lookups, though, a pasted list is perfectly practical.

Building formats beyond SQL

The same method works for generating batches of URLs, command lines and configuration entries. Add https://example.com/ as a prefix to a list of slugs to get full links, or add a command name before each filename to create a script. Always test one line by hand before running the whole generated list.

Check before you run

Run a SELECT COUNT first and compare it with the number of lines you pasted. If you expected 300 IDs and get 287 matches, some may not exist, or hidden characters such as trailing spaces made them differ. Do the check before any UPDATE or DELETE that uses the list.

Try the free Add Prefix / Suffix to Lines
Runs in your browser. No sign-up, nothing to install.

Comments (0)

No comments yet. Be the first to share a thought.