Solved

Defining AS of Date in SQL

Posted on 2014-11-10
2
199 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

617 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