How to Ask a SQL Question That Actually Gets Answered

Readers email me funny pictures, and I love them. Readers also email me questions that say only that the query is slow and please help, and I love those a little less. Here’s how to ask a SQL question that someone can actually answer.

A wooden mannequin hands a neat parcel to a help desk while the next one holds only a single loose screw

Why Some Questions Get Silence

A helper cannot see your screen, your tables or your data. When a question says only that it does not work, the helper has to guess, and most helpers move on to a question they can answer.

It is like calling a mechanic and saying your car makes a noise. The mechanic wants to know what noise, when, and what car. So does every SQL helper I know.

Ask a SQL Question With a Small Script

The best way to ask a SQL question is to send a tiny script that anyone can run: create the table, insert a few rows, and run the query that confuses you.

CREATE TABLE #Orders
(
    OrderId int,
    CustomerId int,
    Amount decimal(10,2)
);

INSERT #Orders (OrderId, CustomerId, Amount)
VALUES (1, 10, 25.00), (2, 10, 40.00), (3, 20, 15.00);

SELECT CustomerId, SUM(Amount) AS Total
FROM #Orders
GROUP BY CustomerId;

Three rows are enough. A helper can paste this and see exactly what you see in ten seconds. Use a temporary table so nobody creates junk in their own database.

Show Expected and Actual Results

Say what you expected and what you got. I expected customer 10 to show 65.00 and I got 25.00 is a question. The total is wrong is a feeling.

Half the time, writing down the expected result shows you the bug before you even send the email.

Include the Version and the Exact Error

Run SELECT @@VERSION and paste the first line. Many answers depend on the version. Copy the full error message with its number, as text. A photo of a monitor taken with a phone is my least favorite way to read an error.

For a slow query, the text of the query is only half the story. Save the actual execution plan from SSMS as a .sqlplan file and share it with the query. The plan shows where the time went, and that is exactly what a helper needs to see.

Before You Ask a SQL Question

Search the error number first. Cut the problem down to the smallest script that still fails. Say what you already tried, so nobody suggests it again. Remove customer names and any private data.

Do these four things and your question moves to the top of every helper’s list, including mine.

Related reading on this blog: Reading SQL Server Error Messages Carefully and Absolute Beginners 10 Queries.

A good question is a gift to the person answering it. It is also the fastest way to your own answer.

Asking for help is not about typing fast, it’s about giving the helper everything they need to see what you see.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

Best Practices, Self Help, SQL Humor, SQL Server
Previous Post
SQL SERVER – Top Five Articles of Year 2008
Next Post
SQL SERVER – Find Row Count in Table – Find Largest Table in Database – T-SQL

Related Posts

1 Comment. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.