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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:52:38+00:00 2026-06-09T18:52:38+00:00

Possible Duplicate: Derived/calculated column on existing table I have SQL Server table with values,

  • 0

Possible Duplicate:
Derived/calculated column on existing table

I have SQL Server table with values, as follows:

Account - Date - Amount - Summary
10000 - 2010-1-1 - 50.00 - 0.00
10000 - 2010-2-1 - 50.00 - 0.00
10000 - 2010-3-1 - 50.00 - 0.00
10000 - 2010-4-1 - 50.00 - 0.00
10000 - 2010-5-1 - 50.00 - 0.00
10000 - 2010-6-1 - 50.00 - 0.00
10000 - 2010-7-1 - 50.00 - 0.00
10000 - 2010-8-1 - 50.00 - 0.00
10000 - 2010-9-1 - 50.00 - 0.00
10000 - 2010-10-1 - 50.00 - 0.00
10000 - 2010-11-1 - 50.00 - 0.00
10000 - 2010-12-1 - 50.00 - 600.00
10001 - 2010-1-1 - 50.00 - 0.00
10001 - 2010-2-1 - 60.00 - 0.00
10001 - 2010-12-1 - 60.00 - 170.00

This is a basic snapshot of the table. The “summary” field gives the total for the amounts at the end of the year on the date column, but only when the MONTH(Date) = ’12’. It goes on this way for hundreds of accounts, with about 4 more years as well. I would like to add a column to this existing table, called “SummaryPreviousYear”. The SummaryPreviousYear column should have the sum of the amounts from MONTH(Date) = ’12’ and the previous year. I’d like to join this column on the account number, so that it sits next to the Summary column and gives a value just like the Summary value does. Can anyone help me with this? I am pulling my hair out here. Any help would be greatly appreciated.

  • 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-09T18:52:39+00:00Added an answer on June 9, 2026 at 6:52 pm

    Presuming that [Account] and [Date] are unique, simply JOIN onto the same table like this:

    SELECT
        a.* -- you should explicitly list the columns you want, though
        ,b.[Summary] SummaryPreviousYear
    FROM
        myTable a
    JOIN
        myTable b
            ON b.[Account] = a.[Account]
            AND DATEPART("yyyy" , b.[date] ) = DATEPART("yyyy" , a.[date] ) - 1
            AND DATEPART("mm" , b.[date] ) = 12
            -- AND whatever other conditions define unique rows
    

    There should be no more than one row having the year-1 and month 12, for any data point. If you want NULL values for the first-year rows, make this a LEFT OUTER JOIN instead.

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

Sidebar

Related Questions

Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: every derived table must have its own alias I need to find
Possible Duplicate: C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived> I have D1 and D2
Possible Duplicate: overloaded functions are hidden in derived class I have Class A and
Possible Duplicate: Ruby on Rails: How can i join with a derived table? posts
Possible Duplicate: Calling virtual function of derived class from base class constructor? I have
Possible Duplicate: Accessing protected members in a derived class If I have an abstract
Possible Duplicate: How to get the address of an overloaded member function? I have
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: When should you use 'friend' in C++? I have come to a

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.