Solved

Defining AS of Date in SQL

Posted on 2014-11-10
2
195 Views
Last Modified: 2014-11-22
I am trying to Define As of Date is use in the code below.  Can someone please look at my code and see if I have it correct.  I also need to show show in the Results this column (END_BAL_A)as BALANCE.  Any other suggestions appreciated.  Using Oracle  11
   
   DEFINE AsOfDate = TO_DATE('07/31/2014','MM/DD/YYYY')


         
SELECT Emp_N, Emp_SHRT_NM,
   SUM(Case when BALANCE>0 THEN 1 Else 0 end) as "# Parts w/ Bal (Total)",
 
   FROM(
      SELECT A.Emp_ID, SUM(END_BAL_A)as BALANCE, A.AS_OF_D
      FROM adbo.V_BAL_MO A      
         
          LEFT JOIN(
                SELECT *--Emp_ID, SSN_ID,
                FROM adbo.V_AT_PART
                 WHERE row_exp_d=TO_DATE('01/01/9999','MM/DD/YYYY')
                 AND Emp_ID IN ('2287')
                ) C ON A.Emp_ID=C.Emp_ID AND A.SSN_ID=C.SSN_ID
         
          LEFT JOIN(
              SELECT *
              FROM adbo.V_FDLLN
              WHERE row_exp_d=TO_DATE('01/01/9999','MM/DD/YYYY')
              AND CUR_LOAN_BAL_A > 0
              ) B ON A.Emp_ID=B.Emp_ID AND A.SSN_ID=B.SSN_ID
       
          LEFT JOIN(
              SELECT Emp_ID, Emp_N, Emp_SHRT_NM
              FROM adbo.V_LA_Emp
              WHERE row_exp_d=TO_DATE('01/01/9999','MM/DD/YYYY')
          ) D ON A.Emp_ID=D.Emp_ID    
         
      AND A.Emp_ID IN ('2287')
   
      GROUP BY A.Emp_ID, A.Emp_ID, A.AS_OF_D
   
)
    WHERE  A.ROW_EXP_D >= AsOfDate
   

GROUP BY Emp_N
0
Comment
Question by:leezac
[X]
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 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40434328
SELECT
      Emp_N
    , Emp_SHRT_NM
    , BALANCE
    , SUM(CASE
            WHEN BALANCE > 0 THEN 1
            ELSE 0
      END) AS "# PARTS W/ BAL (TOTAL)"
   , AsOfDate
FROM (
            SELECT
                  A.Emp_ID
                , SUM(END_BAL_A) AS BALANCE
                , A.AS_OF_D
            FROM adbo.V_BAL_MO A

                  LEFT JOIN (
                        SELECT
                              *--Emp_ID, SSN_ID, 
                        FROM adbo.V_AT_PART
                        WHERE row_exp_d = TO_DATE('01/01/9999', 'MM/DD/YYYY')
                        AND Emp_ID IN ('2287')
                  ) C ON A.Emp_ID = C.Emp_ID
                  AND A.SSN_ID = C.SSN_ID

                  LEFT JOIN (
                        SELECT
                              *
                        FROM adbo.V_FDLLN
                        WHERE row_exp_d = TO_DATE('01/01/9999', 'MM/DD/YYYY')
                        AND CUR_LOAN_BAL_A > 0
                  ) B ON A.Emp_ID = B.Emp_ID
                  AND A.SSN_ID = B.SSN_ID

                  LEFT JOIN (
                        SELECT
                              Emp_ID
                            , Emp_N
                            , Emp_SHRT_NM
                        FROM adbo.V_LA_Emp
                        WHERE row_exp_d = TO_DATE('01/01/9999', 'MM/DD/YYYY')
                  ) D ON A.Emp_ID = D.Emp_ID

                  AND A.Emp_ID IN ('2287')
                  CROSS JOIN (
                              SELECT TO_DATE('07/31/2014','MM/DD/YYYY') AsOfDate FROM dual
                              ) Y
            WHERE A.ROW_EXP_D >= Y.AsOfDate
            GROUP BY A.Emp_ID
                   , A.Emp_ID
                   , A.AS_OF_D
                   , Y.AsOfDate
      ) X
GROUP BY
      Emp_N
    , Emp_SHRT_NM
    , AsOfDate
;

Open in new window

0
 

Author Closing Comment

by:leezac
ID: 40459511
Thank you!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
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…

729 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