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

  • Home
  • SEARCH
  • 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 8228203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:23:07+00:00 2026-06-07T16:23:07+00:00

I am trying to eliminate this division by zero error using CASE in my

  • 0

I am trying to eliminate this division by zero error using CASE in my T-SQL SELECT statement. For some reason, I keep getting the error. Here is my logic.

SELECT 
    CASE 
       WHEN tb1.wpf = 0.000 THEN '0.000' 
       ELSE SUM(tb2.weight/tb1.wpf) 
    END AS Average 
FROM Table1 tb1, table2 tb2 
GROUP BY tb1.wpf

I did not include joins and all my logic to keep my question specific to this case. How can I get rid of this error?

  • 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-06-07T16:23:09+00:00Added an answer on June 7, 2026 at 4:23 pm

    The CASE is going to be applied to the aggregate, not individual bits. Try this:

    SELECT SUM(Average) FROM (
        SELECT 
                CASE 
                   WHEN tb1.wpf = 0 THEN 0
                   ELSE tb2.weight / tb1.wpf
                END AS Average 
            FROM Table1 tb1, table2 tb2 
    ) a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am trying to eliminate outliers in SQL Server 2008 by standard deviation. I
I am trying to eliminate some redundancy, but I appear to be missing something
I'm trying to eliminate some items in an array by checking some other profile
I am trying to figure out how to eliminate line breaks when using add-content
Im trying to eliminate two tables from my database. The tables are message_sort_options and
I am trying to eliminate certain strings from a Description field in a table.
I am trying to eliminate replies and retweets in the twitter widget. So far
Trying to figure out how I can do this properly. The print_r looks like
Trying to copy the msdn refernce here doesn't work and gives an error I

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.