Solved

Defining AS of Date in SQL

Posted on 2014-11-10
2
184 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
2 Comments
 
LVL 48

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

821 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