Need to pull records for full work week two weeks back

I wanted to pull the results from two date fields and calculate the lapsed time. Both dates in the calculation are from the same field, so I used the command feature in Crystal to differentiate the two
SELECT max("A"."CREATED_DATE") as installerContactCreatedDate,
TO_NUMBER("A"."OBJECT_KEY")
FROM "OMS"."AUDITS" "A"
WHERE "A"."ATTRIBUTE_NAME" = 'installerContact'
AND "A"."CREATED_DATE" > SYSDATE - 16
group by "A"."OBJECT_KEY"
SELECT max("A"."CREATED_DATE") as dateScheduledCreatedDate,
TO_NUMBER( "A"."OBJECT_KEY")
  FROM "OMS"."AUDITS" "A"
  WHERE "A"."ATTRIBUTE_NAME" = 'dateScheduled'
AND "A"."CREATED_DATE" > SYSDATE - 16
group by "A"."OBJECT_KEY"
Incidently: u201CAND "A"."CREATED_DATE" > SYSDATE u2013 16u201D was used to limit the results from a huge table and u201816u2019 has no real significance other than trying to return the minimal results for the report.
once I had the above I used this:
datediff("H",{Command.INSTALLERCONTACTCREATEDDATE},{Command_1.DATESCHEDULEDCREATEDDATE})
Now to what I need to do; if I provided too much info I am sorry, I just was hoping to give enough.
I need the results  for a full work week; the catch is I donu2019t need it for the previous week but for two weeks back; i.e. if I ran the report  on Monday the 19th  I want to pull records from the 5th to the 9th
I know that this formula:
{Command.INSTALLERCONTACTCREATEDDATE} in
  CurrentDate - DayofWeek(CurrentDate) - 5
to CurrentDate - DayofWeek(CurrentDate) u2013 1
will pull the prior full business week (m-f); i.e.  ran on Monday the 19th- pulls records for the 12th to 16th, no good for me.
Furthermore, if the field is populated late Friday afternoon and field is not populated until the next week I need to capture that on the following weeks report- eventhough the first part was populated the prior week.
So, report runs Mon. the 19th captures 5th to 9th, but  is populated the 9th and the is not populated til the 12th, 13th, or 14th then that cant show on report for week of 5th to 9th, but on the report for 12th to 16th.
Iu2019d greatly appreciate any assistance and apologize if I made little to no sense when describing my issue.

Try:
SELECT max(case when a.attribute_name = 'InstallerContact'
                    then "A"."CREATED_DATE" else null end) as installerContactCreatedDate,
             max(case when a.attribute_name = 'dateScheduled'
                    then "A"."CREATED_DATE" else null end) as dateScheduledCreatedDate,
     TO_NUMBER("A"."OBJECT_KEY")
FROM "OMS"."AUDITS" "A"
WHERE
("A"."ATTRIBUTE_NAME" = 'installerContact'
   AND "A"."CREATED_DATE" > SYSDATE - 45) 
OR
  ("A"."ATTRIBUTE_NAME" = 'dateScheduled'
   AND "A"."CREATED_DATE" between SYSDATE, - datepart("dw", sysdate) - 13
                                             and SYSDATE - datepart("dw", sysdate) - 7 )
group by "A"."OBJECT_KEY"
having max(case when a.attribute_name = 'dateScheduled'
                    then "A"."CREATED_DATE" else null end) is not null
(where datepart("DW", <date>) returns the day of week.  It's not clear what DB you are using.)
This assumes that the installer date is within 32 days or so of the scheduled date.  Increase the 45 (or remove the date condition altogether - but that would be very slow on a big table) if that's not the case.
sysdate - datepart() returns the prior Saturday,
subtracting 7 days is the end of your week period (Saturday) two weeks ago,
subtracting 13 is the Sunday of your week period two weeks ago.
The case statement within the max() database aggregate functions will be null, and therefore not effect the results, if the attribute name is not the one we are interested in at the moment.
The having clause will restrict the returned records to those objects scheduled within the week of interest.  (Since the WHERE clause is using an OR, there may be records with installerContact date > 45 days ago, but the dateScheduled is not within our week of interest.  In that case, the max() in the HAVING clause will be null.)
And it's all done with one database query! 
HTH,
Carl

Similar Messages

  • Purchase Info Record for Frame work Order

    Hi Friends,
    Do we have Purchase info record for Frame work Order(FO) ?. If yes, Please tell me which info category should i need to select to create a Purchase Info Record.
    Thanks

    Hi
    Is that means, Framework  PO will also use the same standard Purchase info record ?
    Thanks

  • Help with pulling records for the last 24 hours

    Post Author: kbrinton
    CA Forum: Formula
    Hi,
    I don't know what is wrong with me but I can not figure out how to get Crystal to pull records for the last 24 hours.  I have a date field I can key off of but I can not figure out the formula or correct syntax to put in the Selection formula.  Any help would be great!!  Thanks

    Post Author: SKodidine
    CA Forum: Formula
    No need to create any formula.  In your record selection criteria type:
    {table.date} in dateadd("h",-24,currentdatetime) to currentdatetime
    If you just want the prior 24hrs and do not care about the time then replace 'currentdatetime' with 'currentdate'.
    (currentdatetime - 24) will give you 24 days before and not 24 hours.

  • On iPhoto, I can no longer access the 'Classic' option which would lay out my photos on the page. It will send them as attachments only. I need the page layout for my work. Any thoughts as to why this has changed?

    On iPhoto, I can no longer access the 'Classic' option which would lay out my photos on the page. It will send them as attachments only. I need the page layout for my work. Any thoughts as to why this has changed? It used to fully lay out the photos so I could add notes and detailed information before I sent them. I am thinking it is something simple that I have just missed...

    The "Photos" view has been replaced by the Media Browser.
    Most applications will show you the Photos icon in the Sidebar, when you need to select photos in a file chooser dialoge. Mail, Safari, the iWork apps. See Terence Devlin's User Tip: How to Access Files in iPhoto
    For example, in the File > Open dialogue in Preview I am seeing this in the sidebar.

  • Creating a DNS Record for a Host with Two or More IP???

    Can we create DNS A Record for a Host with Two or More IP ... ( we like to use my website  "mysite.com" pointing to two Ips )
    Please help...

    Sure, no worries.
    In a production environment DNS will query always the first record it will stores in cache, you need to find a dynamic or NLB way to achieve the automatic fail over else when you will have an outage with the first IP, then you need to ask your clients to
    clear the cache and register to DNS again, this i will not suggest in a production environment, lots of manual efforts and doesnt sound like a solution in a production environment, i would suggest you to explore windows NLB, it's easy to set and use the OS
    license.
    Thanks
    Inderjit

  • Can anyone guide me how to sync sms on iphone to pc and also what setting need to be done to make sure sms remain in iphone indefinitely - need to keep record for work purpose. thanks.

    Need help from the expert on how to sync sms on iphone to pc and how to make sure that sms on iphone is not being deleted - need to keep sms for office record purpose

    You mean take the cover off of the iPhone, to look inside?  I'd recommend against it.  Even with warranty expired, you might qualify for an out-of-warranty service, which for 3GS is $149.
    Other than that, any repair/service options are going to cost money.  You might want to see if a wireless carrier will let you get a new contract & phone.
    Out of curiousity, you're just using at as, basically, an iPod Touch, if there's no cell provider?  Did I understand that correctly?

  • Why do I keep getting error message from Digital Editions when trying to open it. Keeps telling me that it has encountered a problem and needs to close. I need this apparently to download a text book fro Proquest - need the text book for Uni work what giv

    Why do I keep getting an error message from Digital Editions saying that it has encountered a problem and needs to close. I need this programme to download a text book from Proquest for University work what gives????

    You are using ADE on Windows or Mac ? and their versions ??
    Please restart your machine and try once again.
    Thanks

  • Why my new ipad need boot-strap twice for normally work

    why my new ipad need boot-strap twice for normally work

    why my new ipad need boot-strap twice for normally work

  • My early '06 iMac won't boot, just clicks with question mark on screen. SMC reset, Pram reset can bring it up, works OK for a day or two, then back to no boot. disk utility finds no problem with disk

    anytime I get it to boot, it works for a day or two then goes back to the Question mark screen.

    Hi! It could be HD issue. You should back up your data in the computer first when you can boot to normal desktop. boot to install disk to run disk utility - if it got error over there, you should bring the computer to repair centre to fix it. You also could try to erase with zero out and install again And see will that be fix the issue! 

  • HT1338 i have just purchased a new mac book air and have updated to mavericks after being told in store that iWork was free as i need to use it for uni work and it hasn't come on and is saying i will have to pay £13.99 for pages keynote and numbers

    i have just purchased a new macbook air and installed mavericks but havent recived iwork for free and i need it to do uni work on
    in the store they said nce mavericks was installed this should come free with it how do i go about getting it as in app store it is still charging me 

    Apple - Up-to-Date Program for Pages, Numbers, and Keynote

  • Only backups offered by TM for a full restore are two weeks old.

    I just tried to do a full restore from Time Machine, booted from the install disk.
    When it got to the "chose which back up" step it only offered me three backups, from the 4th, 5th and 6th October.
    The TM drive is an external USB connected directly and has been running regularly without errors. I was to able to enter Time Machine and go to dates much more recent than 6th October.
    I have sorted out the problem which caused the need to restore without TM, but I would like to understand why I couldn't do a full restore from a more recent TM backup, for the future.
    Thanks

    I hope it is OK to paste the prefs file:
    START
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>AlwaysShowDeletedBackupsWarning</key>
    <false/>
    <key>AutoBackup</key>
    <true/>
    <key>BackupAlias</key>
    <data>
    AAAAAAEeAAIAAQhUaW1lTWFjIAAAAAAAAAAAAAAAAAAAAAAAAADG2QQ0SCsAAAAAAAEI
    VGltZU1hYyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAsbZBDQAAAAAAAAAAP////8AAAkAAAAAAAAAAAAAAAAAAAAA
    CFRpbWVNYWMgABAACAAAxtj2JAAAABEACAAAxtj2JAAAAAEAAAACABFUaW1lTWFjIDpU
    aW1lTWFjIAAADgASAAgAVABpAG0AZQBNAGEAYwAgAA8AEgAIAFQAaQBtAGUATQBhAGMA
    IAASAAAAEwARL1ZvbHVtZXMvVGltZU1hYyAA//8AAA==
    </data>
    <key>DestinationVolumeUUID</key>
    <string>017FC86D-0AF0-3AD2-B913-3BE24663D99A</string>
    <key>ExcludeByPath</key>
    <array>
    <string>/Users/michaelb/Library/Calendars/Calendar Cache</string>
    <string>/Users/michaelb/Library/Safari/WebpageIcons.db</string>
    <string>/Users/michaelb/Library/Mail/Envelope Index</string>
    <string>/Users/michaelb/Library/Mail/Metadata/BackingStoreUpdateJournal</string >
    <string>/Library/Preferences/FLEXnet Publisher</string>
    <string>/Users/michaelb/Library/Preferences/ByHost/com.apple.DotMacSync.0017f20 43020.plist</string>
    <string>/Volumes/PERSONAL/Libraries/iPhoto Library/AlbumData.xml</string>
    <string>/Volumes/PERSONAL/Libraries/iPhoto Library/ThemeCache</string>
    <string>/Volumes/PERSONAL/Libraries/iPhoto Library/iPod Photo Cache</string>
    <string>/Volumes/PERSONAL/Libraries/iPhoto Library/Data/iMovie Converted</string>
    <string>/Users/michaelb/Library/Icons/WebpageIcons.db</string>
    </array>
    <key>ExcludedVolumes</key>
    clip
    END
    I am not sure about the first list under "exclude by path". The Users/michaelb/ items are not things I have specified for exclusion. And I certainly didn't change any TM prefs after Oct 6th and today.

  • Need to keep record for each response to each question on quiz. Can this be done outside an LMS?

    For auditing purposes, I need to keep a record of the user's response to each question of a 35 question quiz.
    I don't think my LMS (Halogen) has this capability. Is there a way to keep a record of each slide, outside of screen capturing each response?

    As developing a plugin for Adobe Reader requires a license from Adobe, you will need to send this email into the mailing address found in the Acrobat SDK in the Reader License folder.

  • My comapny has a web based portal for assigning work. Last week I lost the ability to connect to it through a tethered laptop using my Galaxy S5. It worked for the last several years using my drois phones. I can acess it from my home PC, through networked

    I can no longer access my company's web based portal through a tethered laptop. All other web pages work. Has anyone experienced anything like this? It's a verizon problem for sure since I can get to it from every other method...

    It could very well be Verizon where you're able to access from your home PC. But have you tried looking into the Laptops operating system Device Manager to see if that gives any indication of anything, like perhaps possible network driver update?

  • City of origin need to be recorded for PO - and reports required?

    Hi all,
    My client is requiring city of origin report with respect to PO, can you suggest me through which reports we can get city of origin with respect to PO
    regards,
    Sanju

    Hello
    There is no standard report to get the Country of origin for PO line itemwise.
    You can develop a SAP query or Z-report.
    Please do the link as EKPO-EBELN = EKKO-EBELN , EKKO-EXNUM = EIKP-EXNUM, EIKP-EXNUM = EIPO-EXNUM to extact the country of origin dtails for PO line item.
    warm regards
    Ramakrishna

  • I have paid for a Skype number two weeks ago and i...

    I want to know why isn't my Skype numbers on yet when I've already paid for them it still says pending . My other two numbers I paid for before that worked

    Hi, hinepukohurangi, and welcome to the Community,
    As I replied to your post on the Rates & Subscriptions message board, you need to contact Skype Customer Service directly to determine the status of your order as well has how to rectify any issues that prohibit your orders from being processed successfully.
    Here is a link to the instruction on how to contact Skype Customer Service via their secure portal: Contact Customer Service
    If you experience difficulty reaching Skype Customer Service or find yourself redirected back to the Community, please try again using a different web browser and choosing a different path through the various drop-down menu options presented.
    Also, look to approve a pop-up dialogue box which would connect you to start an instant message chat with a customer service agent. If you have pop-ups blocked in your browser settings, this will also block reaching an agent.
    Last and not least, when you reach the last step of the process, remember to click on the "Start Chat" link when you are provided the choice of visiting the Community or starting an instant message chat with a customer service agent.
    Regards,
    Elaine
    P.S. Please, no duplicate posting needed.  Duplicate posts merged into a single topic here.
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

Maybe you are looking for

  • Does airport express need to be connected to Internet to use purely for AirPlay ?

    Does airport express need to be connected to Internet to use purely for AirPlay ? Or can I just attach to my stereo and have my Mac connect directly to it in the absence of a wireless network? Tks

  • Unix System Calls using Java

    Hi! Can anyone tell me how to do Unix System Calls in my Java program? If possible please give me the java code for it taking one unix system call as an example. Thanks in advance Raj

  • Extract All context menu

     Extract All option is missing in my right click Context Menu. I tried to use the restore default file type association and selected  Zip to restore. That did not work. I also used the tutorial from the same forum to install Extract All. That did not

  • Trying to boot from external drive using Startup manager

    Hello forum geniuses I would first like to make an announcement...my loved and cherished iMac G5 has moved on to the next life. Something to do with the motherboard. Your thoughts and prayers are welcome... But some part of her may live on! You see,

  • Running queries against cursor results?

    I'm running a cursor in a stored procedure, and the query itself is dependent on one of the parameters passed to the SP. So, for example: create procedure annoying as SQLString varchar2(50); myCursor Types.cursorType; -- defined elsewhere in pkg. beg