DEV Community

Jason
Jason

Posted on

Build SQL IN Clauses from Text Lists (GUIDs, IDs & Excel Columns)

Every developer has run into this situation.

Someone sends you a list like this:

1001
1002
1003
1004

Or maybe a list of GUIDs copied from logs:

21d611b2-ca84-45bd-80e9-3456d0bf6ac5
bb6c33f3-f142-418d-8414-9b8f33b6f3da
7fe11ef1-2a3b-4c5d-9e8f-1234567890ab

Now you need to build a SQL query like:

SELECT *
FROM dbo.Users
WHERE UserId IN (1001,1002,1003,1004);

or

SELECT *
FROM dbo.ReportTools
WHERE ToolId IN (
N'21d611b2-ca84-45bd-80e9-3456d0bf6ac5',
N'bb6c33f3-f142-418d-8414-9b8f33b6f3da',
N'7fe11ef1-2a3b-4c5d-9e8f-1234567890ab'
);

Typing commas and quotes by hand gets old very quickly.

Common Sources of ID Lists

Most ID lists come from one of these places:

Excel columns
CSV files
API responses
Log files
URL parameters
Email attachments
Database exports

Unfortunately, each source uses a different format.

Some are newline-separated.

Some are comma-separated.

Some are space-separated.

Before writing SQL, you usually have to reformat everything.

Convert Text to a SQL IN Clause

Instead of editing the text manually, you can use the free online generator:

https://comtools.cn/text-to-sql

Paste your list, choose how the values are separated, and generate a ready-to-use IN (...) clause.

The generated SQL automatically:

Adds commas
Wraps string values in quotes
Escapes embedded quotes
Supports Unicode strings using N'...'
Removes blank lines automatically
Example
Input
apple
banana
orange
Output
IN (
N'apple',
N'banana',
N'orange'
)
GUID Example

Input

21d611b2-ca84-45bd-80e9-3456d0bf6ac5
bb6c33f3-f142-418d-8414-9b8f33b6f3da
7fe11ef1-2a3b-4c5d-9e8f-1234567890ab

Output

IN (
N'21d611b2-ca84-45bd-80e9-3456d0bf6ac5',
N'bb6c33f3-f142-418d-8414-9b8f33b6f3da',
N'7fe11ef1-2a3b-4c5d-9e8f-1234567890ab'
)
Supported Delimiters

The tool supports multiple input formats.

Delimiter Typical Source
New Line Excel column
Comma CSV or URLs
Space Logs
Period Numbered lists
Custom Semicolon, Pipe, etc.

That means you don't need to clean the text before generating SQL.

Typical Workflow

A common workflow looks like this:

Copy IDs from Excel

Paste into Text to SQL

Generate IN (...)

Paste into SSMS

Execute SELECT / UPDATE / DELETE
Things to Watch Out For
Numeric IDs

If your database column is an integer, you generally don't need quotes.

Instead of:

IN (N'1001',N'1002')

Use:

IN (1001,1002)
Very Large Lists

If your IN clause contains thousands of values, query performance may suffer.

For large batches, consider using:

Temporary tables
Table-valued parameters
Bulk imports
JOINs instead of large IN lists
Always Test First

Before running an UPDATE or DELETE statement, verify the results with a SELECT.

Instead of:

DELETE ...

Run:

SELECT *
FROM dbo.Users
WHERE UserId IN (...)

Once you're sure the rows are correct, execute the update or delete.

Frequently Asked Questions
Does it work with GUIDs?

Yes.

GUIDs copied from Excel, SQL Server, or logs can be converted directly into an IN (...) clause.

Can I paste an Excel column?

Yes.

Copy the column and paste it directly.

The newline-separated values are detected automatically.

Does it upload my data?

Processing happens inside your browser, making it suitable for routine development work. As with any online tool, avoid pasting confidential production data.

Final Thoughts

Building SQL IN clauses is one of those repetitive tasks developers perform every week.

Automating the formatting saves time and avoids small mistakes like missing commas, mismatched quotes, or accidentally skipping values.

If you frequently copy IDs from Excel, logs, or APIs into SQL Server, a simple text-to-SQL generator can make the workflow much faster.

👉 https://comtools.cn/text-to-sql

sql

database

productivity

webdev

Top comments (0)