Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need sql CASE statement to replace excel formula

Posted on 2016-08-10
5
Medium Priority
?
136 Views
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.
=IF(TDMMYY="0816",(N2+O2),IF(TDMMYY="0916",(N2+O2+P2),IF(TDMMYY="1016",(N2+O2+P2+Q2))))

I think it would start
CASE
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.
case.docx
0
Comment
Question by:actsoft
  • 2
  • 2
5 Comments
 
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
0
 

Author Comment

by:actsoft
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?
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 41751055
WHEN TTMMYY = '0816' THEN [0716]+[0816]
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 41751059
CASE TDMMYY
    WHEN '0816' THEN [0716] + [0816]
    WHEN '0916' THEN [0716] + [0816] + [0916]
    WHEN '1016' THEN ...
    END AS TYSTD
0
 

Author Closing Comment

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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

963 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