need sql CASE statement to replace excel formula

Posted on 2016-08-10
Last Modified: 2016-08-11
I have  a table with field names "0616" "0716" "0816" etc for 24 months. These fields contain numbers.
I also have a field that gets todays date and translates it to "0616" or "0716" etc.
I need a CASE statement to replace this excel formula.

I think it would start
WHEN 'TDMMYY' = '0816' THEN ...
what would the expression be to add the numbers from the fields named "0716" + "0816" + "0916"
please see attached sheet for screen shots that may make this clearer.

As always, Thanks you for your assistance.
Question by:actsoft
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 41751015
= CASE(ddmmyy) WHEN '0816' THEN n2+o2 WHEN '0916' THEN N2+O2+P2 WHEN '1016' THEN  N2+O2+P2+Q2 ELSE 0 END

Author Comment

ID: 41751030
in the table the field names are not "n2" and "o2" they are "0716" and "0816".
so will
WHEN TTMMYY = '0816' THEN 0716+0816
add the amount in those fields together to get the total?
LVL 75

Accepted Solution

Aneesh Retnakaran earned 500 total points
ID: 41751055
WHEN TTMMYY = '0816' THEN [0716]+[0816]
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41751059
    WHEN '0816' THEN [0716] + [0816]
    WHEN '0916' THEN [0716] + [0816] + [0916]
    WHEN '1016' THEN ...

Author Closing Comment

ID: 41752037
That worked with the addition of the full table and field name. thanks

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question