Programming logic needed to retrieve the records for the last month/week

Hi all

I need assistance in programming SQL logic.

Oracle database version: 10.2.0.3.0

Requirement

In an environment of DW, I need to program to weekly and monthly automated batch insert the data from Data_tbl to Reporting_tbl to generate reports. Descriptions of paintings are given below.

Table 1 - Data_tbl (Source of table - this table is updated daily).

Record_dt first name last name


Table 2 - Reporting_tbl_ (the target table)

Cycle_dt first name last name

1. monthly report

In the SQL query, I where clause conditions.

Where Record_dt > = 1 November 08 ' and record_dt < = 30 November 08 '

Using the above condition in development, I'm pulling over the last months data source table data. This will be repeated every month, and it should be automated.
that is, if I run this report at any time in December 2008, he should choose documents dates from Nov 01 to November 30, 2008. If I run this report at any time in January 2009, he should choose documents dates to Dec. 01 to December 31, 2008.
Date values must be assigned for the last month. Value of Cycle_dt in the target table must be the date of the end of last month as on November 30, 2008, 31-dec-2008.


2 weekly Report

In the SQL query, I where clause conditions.

Where Record_dt > ='01-dec-08' and record_dt < ='' 07-dec-08

Monday week start date and end date is Sunday.
If I run the report between the 08 Dec-14 Dec, it should make records of the dates of Dec. 01 to December 7, 2008.
On 15 December, he should seek from 08 Dec-14 Dec.
Value of Cycle_dt in the target table must be the date of last weekend, as on December 7, 2008, December 14, 2008.
Please help me with the logic for both monthly and weekly reports.

Thank you

Hello

TRUNC (dt, 'W') is the beginning of the week, which may be different days, according to the NLS parameters in your session. Unless you want something that varies from one session to the next, you should stick with the weeks of ISO.

TRUNC (SYSDATE + 1, 'IW') - 1

is the Sunday of the week underway Sunday to Saturday, which starts and ends in 1 day before the ISO week.
To find the precedent of the week from Sunday to Saturday:

WHERE   record_dt >= TRUNC (SYSDATE - 6, 'IW') - 1
AND     record_dt <  TRUNC (SYSDATE + 1, 'IW') - 1

If you were interested in a week from Saturday to Friday (either 2 days earlier than the ISO week):

TRUNC (SYSDATE + 2, 'IW') - 2

Tags: Database

Similar Questions

  • Need to retrieve the last line/record in a table

    Hello

    I have a requirement like getting the ending balance of the last record in the table and the same insertion in the opening balance of the immediatetly created the next record.

    In simple terms, I need to extract a value from the last line of the recording.

    For example, I use the query below

    Select rownum emp, empno, ename
    where rownum = (select count (rownum) from emp);

    But, the above query does not return all of the recording.

    Therefore, need help on this.

    Kind regards
    Shivakumar has

    Published by: shiva March 27, 2011 22:14

    Hello
    Strictly speaking there is no such LAST or FIRST folder until that order you them.
    But check the following:

    SELECT * FROM emp MINUS
    SELECT * FROM emp WHERE rownum<=(SELECT count(empno)-1 FROM emp);
    

    Kind regards
    Lakshmi.

  • When I connect to Photoshop CC I still can't go to the program - I need to change the host file?

    When I connect to Photoshop CC I still can't go to the program - I need to change the host file?

    Please follow it mentioned below as follows:

    1 complete the process / Task Manager tasks in the same order, as mentioned below the Manager tasks. See, Open the Task Manager

    • Creative cloud
    • Basic timing & sync to basic support
    • CC library & process CCX
    • Adobe Common Desktop
    • Adobe update daemon
    • Broker CIB Adobe
    • After that, everything that said adobe on it do a force quit for her

    2 - C:\Users\\AppData\Local\Adobe\ MAA UPDATER and two OOBE (App data & Program Data is hidden folder please see, Show files and folders hidden in Windows 7, 8.x, 10, or Vista)

    3 reset the hosts - IP addresses redirected file may prevent you to complete the authorization process.

    4 - CUT any security software installed with firewall system, also if your having any browser Add On installed for blocking advertising that turn off too.

    These changes are temporary you can restore these changes back to normal once your creative cloud app is running *.

    5 - raise the cloud creative app and connect

    Let us know if that helps.

  • I can't open the InDesign program, which I have been using now for over 18 months...  He starts to open then crashes, I uninstalled/re-installed the program and always without success.

    I can't open the InDesign program, which I have been using now for over 18 months...  He starts to open then crashes, I uninstalled/re-installed the program and always without success.

    Hi all

    A hotfix is now available for licensing.

    Please click on the link below and follow the steps.

    Easy steps to follow and should help you to solve the problem.

    https://helpx.Adobe.com/InDesign/KB/crash_on_launch.html

    Thanks and greetings

    Kaushik Afonso

  • For the last few weeks, after that I closed 19.0 FF, I can't open it. I resorted to having to re - install FF each time so that it can open. What should do?

    For the last few weeks, whenever I close Firefox 18 (and more recently 19.0), I can't reopen the browser again. The application runs as if it is going to open, then stops and sits there. I had to resort to the re - install the browser every time now, very irritating. He remembers my tabs as they had been, that I want to. I used to open up to 40-50 tabs, but now made an effort to keep them below 20, thinking that it would help work more optimally. I'm tired of re - install the browser all the time. What should I do? Thank you

    When this happens, check the Windows Task Manager to see if there is a hidden window or the firefox.exe process is at a standstill?

    To open the Windows Task Manager, press Ctrl + Shift + Esc

    On the Applications tab, look for any window with the icon of Firefox. See something wrong here? In another thread, users have reported finding what seems to be a rogue process. If you find something, try to select and killing using end task.

    Under the processes tab, look for firefox.exe. According to the displayed columns, you can often see that the program is reading, writing, communicate or simply sitting there, doing nothing. If you have allowed time to stop Firefox and it crashes, you can select firefox.exe and click on end process.

    After that, Firefox expected to start normally.

    Please see this article for troubleshooting suggestions for when Firefox crashes out. https://support.Mozilla.org/en-us/KB/Firefox-hangs-or-not-responding#w_firefox-hangs-when-you-quit-it

    A little luck?

  • For the last two weeks, I was unable to open all the emails that are in my Windows Live Hotmail folders.

    FOR THE LAST TWO WEEKS IVE HAS BEEN IMPOSSIBLE TO OPEN ANY EMAIL WHICH IS LOCATED IN ANY OF MY HOTMAIL FOLDERS. ALSO, I CAN NOT OPEN HOTMAIL WHICH IS IN THE AREA SENT, WHENEVER I TRY THE SERVER BRINGS BACK ME TO THE HOTMAIL INBOX.
    original title: I CANT ACCESS ANYTHING THAT HASBEN PLACE IN MY RECORDS or IN THE SENT BOX IT JUST FLIPS BACK to MY RECEIVING HOTMAIL Inbox

    Hello

    Given that the problem is related to hotmail, I suggest you to post the question in the forums and check them off below if it helps:
    http://windowslivehelp.com/solutions.aspx?ProductID=1

    It will be useful.

  • In the last months, I started to receive messages pop up when editing pdf files. One is "cannot complete this action because the"filename. " PDF-Adobe Acrobat Pro"program is not responding. "Choose" switch to "and correct the problem. O

    In the last months, I started to receive messages pop up when editing pdf files. One is "cannot complete this action because the"filename. " PDF-Adobe Acrobat Pro"program is not responding. "Choose" switch to "and correct the problem. The other is "content preparation courses. "Please wait while the document is being prepared for" and displays a progress bar. One last question, I noticed it is adobe hangs quite frequently and shows "not responding". I had Adobe Acrobat X Pro for several years, and these have not always taken place only months. I ' n not Adobe expert so I don't know why this is happening. I checked the updates. Any advice on what is happening?

    Hi jeffm7844011,

    Could if it you please let me know the version of the OS on your system?

    Please let me know this happens to you with all the PDF files that you try to change or with specific PDF files?

    Please see this KB document: https://helpx.adobe.com/acrobat/kb/message-content-preparation-progress-opening.html and Windows resolve system errors, freezes | Adobe software .

    Also please try to repair the installation by navigating to the help > repair installation.

    Let me know if it helps.

    Concerning
    Sarojini

  • I had the 'CSXS Infrastructure 4.0.2' update even for the last two weeks

    Every day for the last two weeks, when I came in the creative work cloud tells me that I need to download the new updates. The update is always the same, "assuming CSXS 4.0.2.

    Is what happens to everyone and it is an ongoing update in accordance with or it is download but not really updated the creative cloud?

    Hi Matsonjones,

    This could be a problem that needs to work with our support to resolve. They are accessible via this link http://adobe.ly/yxj0t6

    Hope that helps,

    -Dave

  • For the last month or more, I had the same two updates for my computer

    original title: Windows updates

    For the last month or more, I had the same two updates on my computer.  Is anyone know why and what I can do to fix this?  I am running Windows XP.  Thank you very much.

    Hello

    the message "you have hidden the important updates" is normal, because you have hidden the high priority updates, but the updates are already installed, if that's OK.

    Try to look again at the web page:

    http://www.update.Microsoft.com/

    and click on "Custom".

    You should not see the updates (KB2518864 and KB2539631) in "review and install updates.

    You should see only "Important - you have hidden the important updates..." and "high-priority - updates non-priority updates to update for your computer... ».

    Then, try this (remove the content of the "'C:\Windows\SoftwareDistribution" ")

    1. Click Start, click run, type services.mscand click OK.
    2. In the Services (Local) pane, click automatic updates, and then click stop.
    3. Reduce the Services (local) window.
    4. Select all the contents of the Windows distribution folder, and then delete them.

      Note By default, the Windows distribution folder is located in the drive: \Windows\SoftwareDistribution folder. This place is a placeholder for the drive where Windows is installed.

    5. Ensure that Windows distribution folder is emptyand enlarge the Services (local) window.
    6. In the Services (Local) pane, click automatic updates, and then click Start.
    7. Restart the computer.

    I hope that we will achieve the goal, it will no longer still report the updates :-)

    LC

  • How to complete the data for months current quarter of the last month of the previous quarter

    • Here is the create table and insert the statement how my data is as
      CREATE TABLE SAMPLEDATA (Snapshot_M DATE, Date_Ky DATE, F_Quantities INTEGER)
      INSERT INTO VALUES SAMPLEDATA (SEPTEMBER 1, 2014 ", 1 SEPTEMBER 2014", 14)
      INSERT INTO VALUES SAMPLEDATA (OCTOBER 1, 2014 ", 1 OCTOBER 2014", 13)
      INSERT INTO VALUES SAMPLEDATA (1 NOVEMBER 2014", 1 NOVEMBER 2013', 12)
      INSERT INTO VALUES SAMPLEDATA (DECEMBER 1, 2014", 1 DECEMBER 2013', 11)
      INSERT INTO VALUES SAMPLEDATA (JANUARY 1, 2014 ", 1 JANUARY 2014", 10)
      INSERT INTO VALUES SAMPLEDATA (FEBRUARY 1, 2014 ", 1 FEBRUARY 2014", 90)
      INSERT INTO VALUES SAMPLEDATA (MARCH 1, 2014 ", 1 MARCH 2014", 20)
      INSERT INTO VALUES SAMPLEDATA (APRIL 1, 2014 ", 1 APRIL 2014", 23)
      INSERT INTO VALUES SAMPLEDATA (MAY 1, 2014", 1 MAY 2014', 30)
      INSERT INTO VALUES SAMPLEDATA (JUNE 1, 2014 ", 1 JUNE 2014", 70)
      INSERT INTO VALUES SAMPLEDATA (JULY 1, 2014 ", 1 JULY 2014", 20)
      Desired results set:
      Snapshot_M Date_Ky F_Quantities
      10 1/1/2014-2/1/2014
      10 1/1/2014-3/1/2014
      01/01/2014 41 10/2014
      4/1/2014 5/1/2014 23
      4/1/2014 6/1/2014 23
      4/1/2014 7/1/2014 23

      My requirement is to load the data in the cube.

      So to summarize, data that are loaded onto the month last only a quarter Q1 tax (Jan) should server as a data for the quarter Q2 next month (February, March, April), the data loaded on the last month of Q2 (Apr) will be server as forecast data for Q3 months and so on.

      Thank you in advance.



    with

    SAMPLEDATA as

    (select to_date('09/1/2014','mm/dd/yyyy') snapshot_m, to_date('09/01/2014','mm/dd/yyyy') date_ky, 14 f_quantities of all the double union)

    Select to_date (October 1, 2014 "," mm/dd/yyyy ""), to_date (1 October 2014 "," mm/dd/yyyy"), 13 union double all the

    Select to_date (November 1, 2013 "," mm/dd/yyyy ""), to_date (1 November 2013 "," mm/dd/yyyy"), 12 union double all the

    Select to_date (December 1, 2013 "," mm/dd/yyyy ""), to_date (1 December 2013 "," mm/dd/yyyy"), 11 union double all the

    Select to_date (January 1, 2014 "," mm/dd/yyyy ""), to_date (1 January 2014 "," mm/dd/yyyy"), 10 of all the double union

    Select to_date (February 1, 2014 "," mm/dd/yyyy ""), to_date (1st February 2014 "," mm/dd/yyyy"), 90 union double all the

    Select to_date (March 1, 2014 "," mm/dd/yyyy ""), to_date (1 March 2014 "," mm/dd/yyyy"), 20 union double all the

    Select to_date (April 1, 2014 "," mm/dd/yyyy ""), to_date (1 April 2014 "," mm/dd/yyyy"), 23 union double all the

    Select to_date (May 1, 2014 "," mm/dd/yyyy ""), to_date (1 may 2014 "," mm/dd/yyyy"), 30 union double all the

    Select to_date (June 1, 2014 "," mm/dd/yyyy ""), to_date (1 June 2014 "," mm/dd/yyyy"), 70 union double all the

    Select to_date (July 1, 2014 "," mm/dd/yyyy ""), to_date (1 July 2014 "," mm/dd/yyyy"), 20 union double all the

    Select to_date (August 1, 2014 "," mm/dd/yyyy ""), to_date (1 August 2014 "," mm/dd/yyyy"), 22 of the double

    )

    Select snapshot_m, date_ky, last_value (f_quantities) ignore nulls on f_quantities (order by date_ky)

    of (trunc (add_months (snapshot_m-1), 'q') select snapshot_m, date_ky,)

    -case when trunc (add_months (snapshot_m-1), 'q')! = lag (trunc (add_months(snapshot_m,-1), 'q')) (date_ky order)

    then lag (f_quantities) (date_ky order)

    end f_quantities

    of sampledata

    where date_ky > = date ' 2014-01-01'

    )

    where snapshot_m > = date ' 2014-01-01'

    order of date_ky

    SNAPSHOT_M DATE_KY F_QUANTITIES
    01/01/2014 01/02/2014 10
    01/01/2014 01/03/2014 10
    01/01/2014 01/04/2014 10
    01/04/2014 01/05/2014 23
    01/04/2014 01/06/2014 23
    01/04/2014 01/07/2014 23
    01/07/2014 01/08/2014 20
    01/07/2014 01/09/2014 20
    01/07/2014 01/10/2014 20

    Concerning

    Etbin

  • I have download a creative demo for the last month and created many documents on my computer now change my employer my where are my document or computer how can I get some how?  Thank you

    I have download a creative demonstration for the last month and created many documents on my computer

    Now, my employer just changed my computer where are my document or how can I get some how?

    Thank you

    they are still on the computer you were using (unless someone irretrievably erased).

  • Hello! I ve a problem with the complete abo... How can I activate illustrator after regulation time? the complete abo is already saved for the last month...

    Hello! I ve a problem with the complete abo... How can I activate illustrator after regulation time? the complete abo is already saved for the last month...

    [Duplicate message deleted... post the same question more than once is confusing... MOD]

    [This is an open forum, not a direct line to Adobe support... you have to wait a response]

    Hello

    Please see: -.

    https://helpx.Adobe.com/manage-account-membership/CC-reverts-to-trial.html

  • When you look at the performance of a virtual machine, when you make a graphic of 3 months it appears correctly for the first two, but the last month is compressed.

    When you look at the performance of a virtual machine, when you make a graphic of 3 months it appears correctly for the first two, but the last month is compressed.

    Hello

    When you say that the last two months are compressed. I do not have what exactly you mean by that. Is there a chance you can attach a screenshot of the same thing? Also let me know if there are any made VC-database activity recently?

  • graphic display of performance for the week or the last month?

    Using a VSphere Client 4.1.0 to display an ESX 4.1.0 Server, I am looking at the graph of the performance of the processor (for example).

    When I go into "Options", what I see under CPU options is 'real time' and 'last day '.  Below, time go specifications ('last n periods' and ' a + for ' are all gray.)

    Is there any where that I can set collection or the length to collect & graph interval a longer history, such as week or the last month?

    Thanks for the tips... Lyle

    something greater than what you can buy vmware vcenter.

  • I need to print the last value

    Hello
    in the Sub statement I need to print the last value
    means last 5555, I can print other values, but last value 5555 is I can't print
    Please help me
    SELECT REGEXP_SUBSTR('5454 4587454 547451 188745 5555','[^'||' '||']+'||' ',1,5)  p1 from dual;
    Thanks in advance
    David

    Karthick_Arp wrote:
    Like this

    with t
    as
    (
    select '5454 4587454 547451 188745 5555' str
    from dual
    )
    select regexp_substr(str, ' [[:digit:]]*$')
    from t
    

    Why leave space in front of her?

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select '5454 4587454 547451 188745 5555' str from dual)
      2  --
      3  select regexp_substr(str, '[0-9]+$')
      4* from t
    SQL> /
    
    REGE
    ----
    5555
    
    SQL>
    

Maybe you are looking for

  • GoPro on a Workflow FCPX

    Hello - I found a lot of conflicting answers about this so was hoping I could get this confirmed: is imported directly from GoPro FCPX is going to give you the same quality as in GoPro studio first, import export until. MOV and then use it in FCPX? S

  • get rid of secure search AVG of TABS

    I searched high and low to know how get rid of this research AVG to ensure every time I click on a new tab, I have no arrow or search engine arrows to manage search engines, just what I try does NOT work. Help me I am ready to UNINSTALL my FIREFOX. G

  • Satellite Pro L300 - nothing appears on the screen

    Hello Stupidly, I dropped the phone on the floor and now I can hear the phone turn on and the loading of windows, but I don't see anything on the screen. If I pull the laptop to me, applying light pressure, the backlight turns on, but there is still

  • Vision project of OR can not find the model after migrating to labview.

    HelloMy problem is the following. I did a project with the vision Builder of NOR. Well, it works fine. BUT, when I migrate this labview project (and after that, I build an executable version) it can not find the model on the selected images. (Yes, I

  • virus adware:win32 / open candy

    I tried security security scan full scan no luck couldn't remove just gave me the name how to remove he had two infected slow computer files won't let not my security work or anything like that right can you help me please with losing all my files pl