How can I reference records outside the two date parameters?

Hi all,
I have a query that fetches records based on the two date parameters defined (Startdate and Enddate).
If the Startdate is 2014-12-01 and the Enddate is 2014-12-12, I want to pull records outside these two date parameters, that is      2014-09-01 and 2014-11-30.
I want to add up the records from  2014-09-01 and 2014-11-30 and include them in one of the columns in my report.
I tried using this query:
 SUM(CASE WHEN FilteredIncident.Statuscodename IN ('QUEUED', 'ASSIGNED') AND (EnteredOn >= '2014-09-01' AND EnteredOn<= @StartDate) THEN 1 ELSE 0 END) AS OpenRecords
Please help with any ideas..thanks

Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you probably need to read and download the PDF for: 
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
There is no such crap as a “status_code_name” in RDBMS. It has to be a “<something in particular>_status”; think about how silly that data element name is! Want to keep going and have a “status_code_name_value_id”? LOL! 
The name “Filtered_Incident” is also wrong. Tables are sets, so unless you have only one element in this set, the table name should be a plural or (better) collective name. But a better question is why  did you split out “Filtered_Incidents” from “Incidents”?
Would you also split “Male_Personnel” and “Male_Personnel” from “Personnel”? 
Get a book on data modeling and learn some basics. 
>> I have a query that fetches records [sic: rows are nor records] based on the two date parameters defined (report_start_date and report_end_date). If the report_start_date is 2014-12-01 and the report_end_date is 2014-12-12, I want to pull records [sic]
outside these two date parameters, that is 2014-09-01 and 2014-11-30. I want to add up the records [sic] from 2014-09-01 and 2014-11-30 and include them in one of the columns in my report. <<
Having no DDL and no sample data makes this hard. Does your boss make you program without any documentation, DDL, etc? This spec is vague; you say to do a total, but show a count, etc. 
One of the many nice things about DATE data types is that the BETWEEN predicate works with them, so you can quite writing 1960's BASIC predicates with primitive logic operators. 
Here is a guess: 
SELECT SUM(CASE WHEN incident_date BETWEEN '2014-09-01' 
           AND @report_start_date THEN 1 ELSE 0 END)
       AS open_record_cnt 
  FROM Incidents
 WHERE incident_status IN ('QUEUED', 'ASSIGNED')
    AND incident_date <= @report_end_date; 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • How can I update record in the block that Data Source is PROCEDURE?

    I like use Procedure as the Data Source of block.It's very flexible.
    Usually I do this only query the record,but now I must update record in the block that Data Source is Procedure.
    What next step can I do?Can anyone offer some examples?
    This is example, you goto
    http://www.2shared.com/file/1923834/e0b65fb7/Example.html
    Wait about 30 sec, Click "Save file to your PC: click here",and then you can download it.

    <p>I have written an article about some advanced Forms features.
    Have a look at the 2.3.2 paragraph</p>
    Francois

  • How can I get rid of the extra data page on a pdf?

    Whatever happened to the old pdf creater?  It was so easy to use!  Now I get this extra page of data and the other pages are reversed.  How can I get back to what works?

    Oops!  I use Primo PDF and Nitro, and they both produce the same extra
    page!  I'll ask them, thanks.
    RB

  • Using DW CS6; when uploading a site DW changes all dates to today; how can I upload without changing the file-dates?

    Using DW CS6; when uploading a site DW changes all dates to today;
    how can I upload the site whilst preserving existing file-dates?
    Thanks
    Paul

    How are you uploading?
    I do not see this behavior in DWCS4 or DWCC (I assume nothing changed in DWCS6 and then back for DWCC, but I could be wrong).
    However, when I upload, I only select the files I have modified after an initial "Upload Entire Site? Yes/No" prompt. If you aren't selecting specific files to upload, and you're overwriting the files on your server with new copies of your entire local site each time, the mod dates would show as the date/time of your upload.
    To select only the files that have changed since your last upload...
    1. Right click on your local root folder in the Files window under Local View
    2. Go to Select > Newer Local from the context menu
    3. Wait until DW is done talking to the server, it could take a while, when it's done, all of the files that have a newer mod date locally than their server counterparts will be selected
    4. Click the Put (up arrow) button
    For me, this process never changes the dates of files that aren't part of the upload.

  • How can i make indexes on the Master data table

    Hi Gurus,
    I got a query, in this one i have an Infoobject with many values, like to say invoice number, and i filter and need a lot of Nav Attr of this IO, for this reason the query performance its really bad but i dont know what to do, some friend advice me this : So I would suggest some indexes on the Master data table of your IO for the navigationnal attributer you want to use.
    what else can you tell me? if i put this IO in Line item dimension? , or just with flag high cardinality ? help guys.....

    Hi Jorge.....
    Look.........Line item dimension and High Cardinality r related to each other..............Characteristic which has High Cardinality..we will use it as Line item dimension..........But........A dimension marked as a line item cannot subsequently include additional characteristics.......... This is only possible with normal dimensions...........If u r very sure.............then u can go for Line item dimension............no issues........
    U can also try to Create index..............
    Check this...........
    Re: Indexes on Master Data tables
    Regards,
    Debjani..........

  • How to delete one record out the two?

    Hi all,
    A have an Orders table:
    ACCOUNT, ORDER_NO, ORDER_DATE
    I have a few cases where there two accounts have the same ORDER_NO. I dont think this is right in a traditional Orders/ Orderline relationship!
    For Example:
    ACCOUNT     ORDER_NO     ORDER_DATE
    WYM01     O15506     01/09/2004
    DA4060     O15506     01/09/2004
    What is the best way to delete one of these? There are quiet a few so I was looking into cursors.
    Thanks

    You can do it like this
    DELETE
      FROM orders
    WHERE ROWID IN ( SELECT row_id
                        FROM (SELECT ROWID       row_id
                                    ,ROW_NUMBER () OVER ( PARTITION BY order_no
                                                              ORDER BY ROWID
                                                        ) row_num
                                FROM orders
                       WHERE row_num <> 1
                    );Regards
    Arun

  • How can I get rid of the two-second gap between songs?

    Any help will be appreciated.

    Inside the iTunes program
    Right click on the iPod icon
    Select 'iPod options'
    Select 'Playback' folder
    I use a 6 second crossfade playback - kind of like FM radio programming phases a song in or out
    Hope this helps!
    Chilly

  • How can i write and read the same data

    hi,
             i have attached my program to this mail. i have some problems in this program.
    problems:
    1. I want to select the threshold for the rms,varience and s.d.
    But what i used is not doing that. i want to fix the upper threshold value and lower threshold value.
     when ever the input crosses upper threshold value i want the output and it will remains uptill the value above the lower threshold value.
    Once it come down the lower threshold value the output should be stopped.
    2. I want to write this in to a  file and i want to read this file. is this possible or not. 
                please try to help me i am very new with lab view6i
           REGARDS
    CHAMARTHY KOMAL DILEEP.
       [email protected]
    Attachments:
    dileep.vi ‏93 KB

    The easiest way to perform a certain action (such as file I/O) based on a certain condition (such as whether a value has passed a certain threshold) is to use a comparison VI in combination with a case structure. Then you can specify that if your rms, standard deviation and variance are above a threshold then perform a certain action.
    Also consider using shift registers to keep track of data from the last loop. If I understand you correctly, you want to start logging data when an upper threshold has been passed. Then you want to continue logging data until a lower threshold is passed. I have attached a non-functional but explanatory VI that will help explain how to implement logic to that effect. It also demonstrates that you can indeed write and read from the same file in a loop. The best way to do this is to open the file before the loop, do all the necessary writing and reading in the loop, and then close the file after the loop.
    Hope this helps!
    Jarrod S.
    National Instruments
    Attachments:
    dileep_example.vi ‏61 KB

  • How can I reference the last value in a column?

    How can I reference the last value in a column? For example, today I want the value of A1 to appear in another cell. Tomorrow, I will add a row and want to reference A2, next day A3, and so forth.

    Now I got it:
    =OFFSET(A1,COUNT(A)-1,0)

  • How can I purchase products from the app store while travelling outside my country of residence?

    How can I purchase products from the app store while travelling outside my country of residence? We are from Canada, travelling in the USA and wish to buy a TV series but get a message to buy it from the Canadian store. When we tried to do this we got the same message.

    According to the terms of sale, you have to be in your country of residence in order to make a purchase. I've heard of people able to make purchases outside their country and also of people being unable to do so. It appears that Apple's enforcement is not 100%.
    In order to buy from the U.S. iTunes Store, you would need to have a valid billing address in the U.S., a credit card billed to that address or an iTunes Gift card purchased in the U.S. and be physically present in the U.S. at the time of purchase.
    International copyright law is currently very inconvenient for the consumer.
    Best of luck.

  • How can I link specific cells in two different speadsheets so the data from a specific cell in spreadsheet A automatically updates in a specific cell in spreadsheet B. It works in Xcel- Any ideas?

    How can I link specific cells in two different tables so the data from a specific cell in table A automatically updates in a specific cell in table B? It works in Xcel- Any ideas?

    (1) your title ask the way to link different spreadsheets.
    In Numberland, a spreadsheet is an entire document.
    There is no way to link different documents.
    (2) in the message, you ask the way to link different tables.
    This feature is available and is described in iWork Formulas and Functions User Guide (which is available for free from the Help menu).
    Getting the info just requires a simple search in this available resource !
    Yvan KOENIG (VALLAURIS, France) 14 mai 2011 10:37:50

  • I use Exchange to sync my iphone4S with Outlook.  On my iphone, my contacts are split into multiple records if they have more than one email address - how can I consolidate them on the iphone

    i use Exchange to sync my iphone4S with Outlook.  On my iphone, my contacts are split into multiple records if they have more than one email address - how can I consolidate them on the iphone

    I have loaded my Firefox bookmarks into Internet Explorer Favorited. I also uninstalled Safari.
    I go to iTunes on my phone and see no wat to connect my iPhone to my laptop. I see Music, Shows, etc., the kind of stuff I would expect, but no clue as to how to proceed.
    Would you please be so kind to fill me in on how to "That syncing is done via iTunes. Connect the device to iTunes, select it, then go to the Summary page and select to sync bookmarks."?
    I am not sure what you mean by "Summary Page"
    Thank you

  • I purchased three albums last week and only two of them were charged.   How can I make sure that the third album gets charged in a timely fashion?

    I purchased three albums last week and only two of them were charged.   How can I make sure that the third album gets charged in a timely fashion?

    Well, thanks for feeling with me, patkosanke ... AND for your wise advice.
    I did followed your advice immediately and erased all the service number as well as S/Ns.
    Can you, however, give me any "direct number" through which I can get hold of someone and request for what you're suggesting?
    I believe I had talked with the person by the name of "Charlie" (I think... I hope I'm correct...) when I was having the same problem with the last device. He was very kind and helpful, though I ended up getting the device that brought the same problem.
    Charlie told me that if I had any more problems I should call him. But I forgot to take down his direct number.
    Or maybe I should call the main office and ask for him. But my memory is questionable as to his name, and besides I don't even know his last name either. There could be more than one "Charlies" in Palm.
    So, if you could somehow email me some direct number (other than the one that keeps on hooking me up with those people in the overseas who are answering the phone only to sympathize with & apologize to me but can only issue a false hope with the SRO#. More than once I was given the promise that the supervisor would call me back within an hour or two but I ended up calling back after I had been left hanging in the air all night long.) where I can talk to someone like I did with Charlie last time who can truly carry out the promise, I would truly appreciate it, patkosanke. ^^
    Thanks
    jcinlovewpalmTX
    Post relates to: Palm TX
    Post relates to: Palm TX
    Message Edited by jcinlovewpalmTX on 03-05-2009 06:36 PM
    Message Edited by jcinlovewpalmTX on 03-05-2009 06:36 PM

  • I own two i macs. I bought and installed Lion on one computer. How can I install Lion on the other computer without additional charge?

    I own two I macs. I bought and installed Lion on one computer. How can I install Lion on the other compute without additional charge?

    If it's the same email address Apple registration on both, use the 2nd computer and go to the App Store and find Lion. If different, use the second computer but log in to the App store with the address you used on the first go round. The buy button should instead say install. Then go through the same process again.

  • I have two iPhones and an iPad under same Apple ID. How can I change one of the iPhones to a separate id?

    I have 2 iPhones &amp; an iPad under 1 Apple ID. How can I change 1 of the iPhones to a separate account?

    Sign out of the Apple ID on the device in question, making sure to disable the Find My iDevice feature.
    Sign in with the new Apple ID.
    If the intent is to sell the device, simply restore as new after disabling the Find My iDevice and signing out.

Maybe you are looking for