Solved

need help to write SQL

Posted on 2011-09-28
4
345 Views
Last Modified: 2013-11-16
How to write a SQL for the following?  Thanks for the help!

INQREG      Wtd avg pay      Factor
<=0      <= 22                       0.905
<=0      > 22                       0.905
>0      <= 22                       1.000
>0      > 22                       1.257
0
Comment
Question by:jjxia2001
  • 2
4 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 36812872
You didn't provide very much information (please provide as much information as possible when posting questions!)  What is your table structure?  What does "Factor" mean?

The conditions you list will display all results (you have all cases enumerated).  Are you looking for separate queries for each?
0
 
LVL 2

Expert Comment

by:sanofi-aventis
ID: 36815076
I would assume your trying to get the appropriate factor.

This versin matches exacly what you have above.
Case When INQREG <= 0
     THEN ( CASE WHEN Wtd_avg_pay <= 22
                 THEN 0.905
                 ELSE 0.905 END )
     ELSE ( CASE WHEN Wtd_avg_pay <= 22
                 THEN 1.000
                 ELSE 1.257 END )
     END AS Factor

But could be simplified since the rate is identical if INQREG <= 0 no mater what the week-to-date average pay is
Case When INQREG <= 0
     THEN 0.905
     WHEN Wtd_avg_pay <= 22
     THEN 1.000
     ELSE 1.257 END AS Factor

Test SQL;
Proc SQL;

      SELECT Case When INQREG <= 0
                      THEN 0.905
                      WHEN Wtd_avg_pay <= 22
                      THEN 1.000
                      ELSE 1.257 END AS Factor1,
               Case When INQREG <= 0
                      THEN ( CASE WHEN Wtd_avg_pay <= 22
                                  THEN 0.905
                                  ELSE 0.905 END )
                      ELSE ( CASE WHEN Wtd_avg_pay <= 22
                                  THEN 1.000
                                  ELSE 1.257 END )
                      END AS Factor2
        FROM WORK.TEST;

QUIT;


Best of luck;
T-Bone

     
0
 
LVL 2

Accepted Solution

by:
sanofi-aventis earned 500 total points
ID: 36815129
This could also be used in the WHERE clause like this

Proc SQL;

      SELECT T2.*, T1.*
      FROM TEST    AS T1,
           FACTORS AS T2
      WHERE Case When T1.INQREG <= 0
                       THEN 0.905
                       WHEN T1.Wtd_avg_pay <= 22
                      THEN 1.000
                      ELSE 1.257 END = T2.Factor;

QUIT;

T-Bone
0
 

Author Closing Comment

by:jjxia2001
ID: 36818157
thanks!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 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