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 9153635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:18:18+00:00 2026-06-17T12:18:18+00:00

How can I replicate following in LINQ SELECT KEY_COLUMN, CASE WHEN SUM(COLUMN2) < 0

  • 0

How can I replicate following in LINQ

SELECT KEY_COLUMN,
        CASE WHEN SUM(COLUMN2) < 0 THEN SUM(COLUMN2) ELSE 0 END AS NewColumn
FROM TABLE
GROUP BY KEY_COLUMN

till now I could come up with following

var result = from a in source
               group a by a.Key_Column
                   into g
                   select new
                   {
                       Key_Column = g.Key,
                       NewColumn = g.Where(item => item.Column2 < 0)
                                    .Sum(item => item.Column2)
};

above code is not really summing up the Column2 before deciding if it’s a negative number or not.

  • 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-17T12:18:19+00:00Added an answer on June 17, 2026 at 12:18 pm
    var query = from a in db.Table
                group a by a.Key_Column into g
                let sum = g.Sum(item => item.Column2)
                select new {
                   Key_Column = g.Key,
                   NewColumn = sum < 0 ? sum : 0
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to replicate a T-SQL statement that has an inner select, using LINQ:
Can someone help me replicate the following scenario: I'm having a activity A with
I need to replicate the following working HQL query using criteria API. session.CreateQuery( select
I wonder if someone can help me. I want to replicate the following SQL
I'm looking to replicate the following within my application: As you can see, its
Ok, I am trying to replicate the following SQL query into a Linq expression:
How can we replicate the following sql query in MongoDb? update Person set Alias
What kind of page (Pivot/Panorama) can we replicate the following? It seems to be
I have the following crash that I can't replicate on demand but does happen
I know a view is composed of tables. Can I replicate a view anyway?

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.