How can I retrieve last month and last mont -1?

Hi guys, I am finishing to build a complex SSIS package, the last task is pretty simple but I'd like you to suggest the better solution in terms of performance (table with millions rows). The task is to create two table, one with the last update (archived)
and one with the last update -1 (the update is done monthly) taking the data from an huge table (create by the package).
The DDL (sample):
create table forum (runner varchar(20), race varchar(20), nmonth varchar (6), archived datetime2)
insert into forum values ('Zabres','Poland Red Bull','201411','2015-01-26 11:37:02.6870000'),
('Reynolds','Poland Red Bull','201411','2015-01-26 11:36:02.6870000'),
('Greefer','Poland Red Bull','201411','2015-01-26 11:38:04.6870000'),
('Zabres','France Red Bull','201411','2015-01-26 11:38:10.6870000'),
('Reynolds','France Red Bull','201411','2015-01-26 11:36:02.6870000'),
('Greefer','France Red Bull','201411','2015-01-26 11:36:02.6870000'),
('Zabres','Poland Red Bull','201411','2014-12-31 16:22:02.6870000'),
('Reynolds','Poland Red Bull','201411','2014-12-31 16:26:02.6870000'),
('Greefer','Poland Red Bull','201411','2014-12-31 16:26:14.6870000'),
('Zabres','France Red Bull','201411','2014-12-31 16:22:02.6870000'),
('Reynolds','France Red Bull','201411','2014-12-31 16:22:02.6870000'),
('Greefer','France Red Bull','201411','2014-12-31 16:22:02.6870000'),
('Zabres','Poland Red Bull','201411','2014-12-11 10:30:14.5870000'),
('Reynolds','Poland Red Bull','201411','2014-12-11 10:31:10.5550000'),
('Greefer','Poland Red Bull','201411','2014-12-11 10:31:14.3560000'),
('Zabres','Poland Red Bull','201411','2014-12-11 9:11:14.4420000'),
('Reynolds','Poland Red Bull','201411','2014-12-11 9:11:54.7760000'),
('Greefer','Poland Red Bull','201411','2014-12-11 9:11:55.7860000')
The tough thing is the format of archived. How can I take the last month and, especially, the last month -1 without caring about the seconds and milliseconds ?
The expected is LAST MONTH
LAST MONTH -1
Many thanks in advance

Yes! Your solution looks better, even in terms of performance (242 sec mine, 202 sec yours). Now I'm wondering the same, shall I upload the elements only once per month? What if I got more upload in one month?
You can also upload it once per week
In which case query would be like
SELECT *
FROM forum
WHERE archived >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND archived < DATEADD(wk,DATEDIFF(wk,0,GETDATE())+1,0)
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How can I retrieve my contacts and pictures after installing iOS6 on my iphone?

    How can I retrieve my contacts and pictures after installing iOS6 on my iphone? Don't call me stupid! I was relying on iCloud to have backed all this up, but turns out it didn't work. Can anyone help me get my photos back - they were of my baby daughter. Also, I've lost all my contacts. Please help.

    Unfortunately no. The only way the phone backs up is if you make it back up. You either connect to iTunes and backup and sync, or you set it up for a wifi sync to iCloud. But you have to setup iCloud to start with. You have learned a hard lesson on how to make sure you import pictures on a regular basis like you would the digital camera. When things happen to the phone, this is the media that is lost the most (pictures in camera roll). After taking a number of pictures, and especially ones you consider important, you should connect the phone to the computer and import them, so there is a backup copy on the computer.
    Contacts are saved in the backup as well, however they are really designed to be synced to a supported application on the computer, or backed up to iCloud or other cloud service. And, the only way to go back in time on the phone is to restore from a backup, but you also have to remember, you would lose everything on the phone that you had done since that backup, so it is a double edged sword.

  • HT201559 my iphone 4 has completely died.. how can I retrieve my contacts and photos from icloud?

    my iphone 4 has completely died.. how can I retrieve my contacts and photos from icloud?

    Hi you can take to Apple Store they may Replace with a Refurbished, one but you will need to pay part of cost. Make an Appointment, if you do get Another iphone when you set it up Just use the same Apple, id & password then you will get all your Apps & Data back. Cheers Brian

  • How can I retrieve Aperture Previews and Thumbnails directly after a corrupt hard drive corrupted Masters?

    I have several old albums where JPG's were apparently corrupted on an old striped RAID.
    Aperture still shows the previews (quite large, thankfully) for these old images.
    But when Aperture tries to refresh the preview, the previews mimic the corrupt masters.  To stop the bleeding, so to speak, I renamed my Master directory so Aperture doesn't update previews for these corrupt JPGs.  However, I'd really like to save these previews, even if not at full resolution. Some folders
    How can I retrieve Aperture Previews and Thumbnails for these items?
    My process so far:
    1) Show package contents on Aperture Library.
    2) Navigate to Previews
         - some directories are here, some are missing
         - for those that are here, back up elsewhere and mission accomplished
         - for those that are missing, try to recover the thumbnails at least...
    3) Navigate to Thumbnails
         - Lots more directories here. Likely the ones I'm looking for. (but they have strange hash names, so it's hard to say)
         - BUT, they only show large "AP.Thumbnails" files, no separate image file
    The big answer I'm looking for... How to recover images missing from Preview directory and/or AP.Thumbnails files? (short of taking screenshots)

    It would be nice to know your Aperture and OS version, there have been changes over the years.
    The big answer I'm looking for... How to recover images missing from Preview directory and/or AP.Thumbnails files? (short of taking screenshots)
    If you open the library in Aperture you can drag the preview images out of the browser and place them in a folder on your HD.  If you cannot open the library then you will have to resort to going into the library package and rooting around.  There was a big  change with the library layout from Aperture 2 to 3 so knowing the version would really help here.
    regards

  • TS3274 How can I retrieve the iTunes and App icons to my home screen?

    How can I retrieve the missing iTunes and App icons to my iPad home screen?

    If you can't find them on any of your homescreens or app folders, and you can't find them via the spotlight search screen (swipe your first home screen to the right), then are they hidden by Settings > General > Restrictions > Installing Apps and iTunes being set 'off' ?
    If not then have you tried a reset to see if you can find them after the iPad has restarted ? Press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • How can I display the first and last name using a paramater as employee ID?

    Hi SAP,
    I have a parameter that is called {? Employee ID}.   What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report.  Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
    if table.employeeid = {? Employee ID} then
    table.firstname" "table.lastname
    It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
    Anyone have any ideas?
    Z

    Hi Try this,
    Whileprintingrecords;
    if ={?EmpID} then
    Also check the option "Default values for null" in the formula editor.
    Regards,
    Vinay

  • How can i get the month and year of the current  open Periode?

    At the beginning of each month the booking period for the new month was not open,but i need to book material automatically with the last day of the old month. The booking period will change at the first working day between 13 and 17 a clock. when the booking period was changed i have to book with the current date.
    How can i do this ??
    Regards
    Ralf

    Hi Ralf,
    here's a complete example:
    DATA: last LIKE sy-datum, "ultimo of last month
          gjahr LIKE t001b-frye1,
          buper LIKE t001b-frpe1.
    last = sy-datum - sy-datum+6(2) .
    PERFORM check_period.
    IF sy-subrc <> 0.
      ADD 1 TO last . "-> next month
      PERFORM check_period.
      IF sy-subrc <> 0.
        MESSAGE a001(00) WITH 'no open fi period'.
      ENDIF.
    ENDIF.
    *formatting for germany
    CONCATENATE last+6(2) last+4(2) last(4) INTO bbkpf-budat.
    WRITE: / bbkpf-budat.
    FORM check_period.
      MOVE last(4) TO gjahr.
      MOVE last+4(2) TO buper.
      CALL FUNCTION 'FI_PERIOD_CHECK'
           EXPORTING
                i_bukrs          = bbkpf-bukrs
                i_gjahr          = gjahr
                i_koart          = '+'
                i_monat          = buper
           EXCEPTIONS
                error_period     = 1
                error_period_acc = 2
                OTHERS           = 3.
    ENDFORM.                    " check_period
    regards <a href="https://www.sdn.sap.com:443/irj/servlet/prt/porta
    l/prtroot/com.sap.sdn.businesscard.SDNBusinessCard?u=i
    Wo3ssHlIihvCrADIEGqaw%3D%3D">Andreas</a>
    Message was edited by: Andreas Mann

  • HT201302 I deleted my photos from my i phone thinking they would be on my i pad, they are no where i can't find them anywhere how can i retrieve my photos and videos? anyone help.

    Can I retrieve my deleted photos and videos somehow?  I deleted my photos from my iphone thinking they would be on my ipad.  Now all of my photos and videos are gone some one please help.

    Hello queen cash
    If you have a back up either in iTunes or in iCloud before you deleted the pictures, then you can restore that back up back on your iPhone. Also note you will not have anything that you have currently on your iPhone, as it will remove the current data and put what the back up had on it. If you where using iCloud and using Photo Stream, make sure you are on Wi-Fi and have closed out the Camera app as it will prevent it from uploading the photos. 
    iOS: Back up and restore your iOS device with iCloud or iTunes
    http://support.apple.com/kb/ht1766
    Regards,
    -Norm G.

  • How can i know the month and year when my ipod classic was manufactured ?

    assuming i only have its serial no.

    Hi Ralf,
    here's a complete example:
    DATA: last LIKE sy-datum, "ultimo of last month
          gjahr LIKE t001b-frye1,
          buper LIKE t001b-frpe1.
    last = sy-datum - sy-datum+6(2) .
    PERFORM check_period.
    IF sy-subrc <> 0.
      ADD 1 TO last . "-> next month
      PERFORM check_period.
      IF sy-subrc <> 0.
        MESSAGE a001(00) WITH 'no open fi period'.
      ENDIF.
    ENDIF.
    *formatting for germany
    CONCATENATE last+6(2) last+4(2) last(4) INTO bbkpf-budat.
    WRITE: / bbkpf-budat.
    FORM check_period.
      MOVE last(4) TO gjahr.
      MOVE last+4(2) TO buper.
      CALL FUNCTION 'FI_PERIOD_CHECK'
           EXPORTING
                i_bukrs          = bbkpf-bukrs
                i_gjahr          = gjahr
                i_koart          = '+'
                i_monat          = buper
           EXCEPTIONS
                error_period     = 1
                error_period_acc = 2
                OTHERS           = 3.
    ENDFORM.                    " check_period
    regards <a href="https://www.sdn.sap.com:443/irj/servlet/prt/porta
    l/prtroot/com.sap.sdn.businesscard.SDNBusinessCard?u=i
    Wo3ssHlIihvCrADIEGqaw%3D%3D">Andreas</a>
    Message was edited by: Andreas Mann

  • How can I retrieve my photos and media from icloud backup?

    I bought the new 4s yesterday and restored my phone with backup from the iphone 4. I got everything except the photos and my songs. I know they are in the icloud because I have always backed them up. How can I retreive them?

    If you setup iCloud on the iPhone then tap Settings > iCloud
    Switch Photo Stream on.

  • How can you retrieve the GRPNO and SRVID in a server?

    Hi,
    Is there a way within a server (e.g. in tpsvrinit) of retrieving the -g and -i
    parameters passed to the server at startup? (these are visible if you use the
    "tmboot -d1" option). We have multiple instances (over 100) of servers that use
    the same executable, but we are unable to determine which messages in the ULOG
    come from which server (as there is no means of tying the pid to the group/server
    id). What we would like to do is display a message at startup that gives the
    group id and server id, and also include this info in subsequent ULOG messages.
    Any and all suggestions will be gratefully received!
    Thanks & regards,
    Malcolm.

    Hello Malcolm,
    you might want to try using the MIB_SELF flag while calling the MIB for the T_SERVER
    class.
    Hope this helps,
    /Per
    "Malcolm Freeman" <[email protected]> wrote:
    >
    Hi,
    Is there a way within a server (e.g. in tpsvrinit) of retrieving the
    -g and -i
    parameters passed to the server at startup? (these are visible if you
    use the
    "tmboot -d1" option). We have multiple instances (over 100) of servers
    that use
    the same executable, but we are unable to determine which messages in
    the ULOG
    come from which server (as there is no means of tying the pid to the
    group/server
    id). What we would like to do is display a message at startup that gives
    the
    group id and server id, and also include this info in subsequent ULOG
    messages.
    Any and all suggestions will be gratefully received!
    Thanks & regards,
    Malcolm.

  • HT5824 how can i retrieve my photos and notes ?

    My ipad mini stopped working in July, and Apple replaced it with a new device, however i lost all my notes and photos, so from the lesson learnt i have been taking downloads into my laptop. Today, when i tried the same, it displayed the new serial number of the new device(which hadn't happened during the last few backups) and aked me if its the same users as (previous ipad name) i agreed, and then all my current data between starting use of new device and today vanished without being downloaded, AND all the stuff in the previous data from the old device is back !!! I m stumped cos i have no clue what happened, i desperately need my data back, unable to restore through icloud, though my photostream handle was on...I'm very hopeful though, cos all that i had lost earlier, just came back today, just dont know how, so that i can do it again, request for advice and inputs, on how to get to the screen that asked me if i it was the same ipad and started restoring all the previous data... Plz help...Thanks in advance...

    Welcome to the Apple Community.
    Photos in photo stream...
    You can log into your iCloud account on another computer or device and enable photo stream to see your photos. You should do this as soon as possible because photo stream in the cloud only keeps photos for 30 days and each day you delay, you will lose another days photos.
    Photos in the camera roll...
    If you kept a back up of your device you can use it to restore to a replacement device, this will restore all of the photos in your camera roll and isn't time limited.

  • How can I retrieve my playlist and download to this computer.

    Please advise how I retrieve my play list of purchased song and download to this computer.  The playlist was on a computer that crashed.  Help???

    If all of these tracks were purchased from iTunes, you can transfer them to your new iTunes library by plugging in your iPod and choosing File -> Transfer Purchases from iTunes.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    B-rock

  • How can I retrieve my photos and videos after pressing 'delete from everywhere' accidentally on my iPhone 4s?

    Hello all,
    So I was organising my photos and videos on my iPhone 4s and wanted to delete them from my camera roll once I had moved them to new folders. When I tried to delete them from my camera roll it asked if I wanted to 'delete from everywhere'. Not knowing what this button did I pressed it and have now lost all the copies of those photos and videos I had taken!!!
    Is there any way of retrieving them off of my iPhone? Is there like a recycle bin type folder where all the deleted data has gone to from where I can recover it?
    Hope someone can help.
    Thank you

    Your backup contains photos and videos from the camera roll, if you did not sync after that, use the latest backup to restore from: iTunes: About iOS backups and Backing Up, updating, and restoring your iPhone and iPod touch software

  • How can i retrieve losr contacts and purchased music fron i tunes if my computer failed and now has none of these saved on my itunes to restore back on my replacement phone?

    right, i was restoring my phone from back up last night as i got a new handset because of a defective screen and during the resore my lap top froze, so i had to restart it. then when i had done i could no longer restore from back up and only sync the phone,so i did and there was no music,photos,contacts or apps available from itunes to put back on my phone,where has this media gone? it must be somewhere surley?
    many thanks
    neil

    Restarting your computer does not cause media to disappear.
    Does your music, photos, apps still exist on the computer?
    iTunes is not a photo or contact manager, so you would need to verify that those items exist elsewhere.
    If you are solely reliant upon iTunes to backup your contacts, you may be in trouble.
    iTunes places the backup files in the following places:
    Mac: ~/Library/Application Support/MobileSync/Backup/
    Windows XP: \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
    Windows Vista and Windows 7: \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
    Do you have backup files in the above listed locations?
    Seems to me that you have two issues:
    Content missing from iTunes
    Content missing from iPhone.
    Once the first issue is resolved, then it will be very easy to resolve the second.

Maybe you are looking for