Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:54:28+00:00 2026-05-31T07:54:28+00:00

I am in the habit of using a stringbuilder to build up an Sql

  • 0

I am in the habit of using a stringbuilder to build up an Sql statement to execute, as this allows me to keep the statement formatted and readable in the code. However it can produce an inefficient statement with lots of extra whitespace:

sb.AppendLine (@"SELECT DISTINCT *");
sb.AppendLine (@"    FROM (  SELECT col1");
sb.AppendLine (@"                 ,  col2");
sb.AppendLine (@"                 ,  col3 ");
sb.AppendLine (@"                 ,  col4");
sb.AppendLine (@"              FROM (SELECT *");
sb.AppendLine (@"                      FROM TABLE )";
sb.AppendLine (@"             WHERE col5= col1 ");
sb.AppendLine (@"             AND col6 = col2 ");
sb.AppendLine (@"          GROUP BY col1");
sb.AppendLine (@"                 ,  col2");
sb.AppendLine (@" ORDER BY col3");

this sql is an example of the issue and may not even be correct.

Should I strip the whitespace from this before I pass it to to a command object to be executed? Or will the command do this itself, or is this just a micro optimization which is not worth thinking about?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:54:30+00:00Added an answer on May 31, 2026 at 7:54 am

    This is how I declare my SQL queries in the code:

    string query = @"
        select columns
        from table
        where condition = 1
    ";
    

    Here are the pros:

    • Way better readability, no clutter
    • I can easily copy the SQL block to/from a SQL client tool
    • A version control diff tool will easily show me what has changed in the query only.

    No cons so far 🙂

    Update

    Oh, and, yes, I think worrying about extra white spaces is over-optimization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Out of habit I've been using try/catch blocks in my application code for all
I've gotten in the habit of using a general catch statement and I handle
I am always in the habit of using if, else-if statement instead of multiple
I've got into the habit of using Closures everywhere I can in place of
I've got into this habit of always using unsigned integers where possible in my
I have a bad habit of using the cursor keys of my keyboard to
im using linux with gedit which has the wonderful habit of creating a temp
PHP has the habit of evaluating (int)0 and (string)0 as empty when using the
I have this horrible habit of typing the below and not catching it until
So I've gotten in the habit of using WPF/C# value converters because they are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.