Putting a specific date range in an SQL query

Hello team,
I have a query that i have to run every month but still i have to extract information for a given time period.
Please advise.

SELECT gcard.ncrd as "CARD NUMBER",
GPCSTMER.TFNAMCSU || ' ' || TNAMECSU "CUSTOMER NAME",
TO_CHAR(GCARD.DISSUCRD,'DD-MM-YYYY') AS "FIRST ISSUE DATE",
case when GCARD.CRSVLCRD = '000' then 'VALID '
when GCARD.CRSVLCRD = '001' then 'LOST CARD '
when GCARD.CRSVLCRD = '002' then 'STOLEN CARD '
when GCARD.CRSVLCRD = '004' then 'FAULTY CARD '
when GCARD.CRSVLCRD = '005' then 'RETURNED CARD '
when GCARD.CRSVLCRD = '006' then 'STOP CARD '
when GCARD.CRSVLCRD = '007' then 'SUBSTITUTED CARD '
when GCARD.CRSVLCRD = '008' then 'CARD NOT ACTIVATED'
end "CARD STATUS ",
CASE
WHEN Gaccount.CSTATACT = '000' THEN 'NORMAL '
WHEN Gaccount.CSTATACT = '001' THEN 'GREYLIST '
WHEN Gaccount.CSTATACT = '002' THEN 'CLOSED '
WHEN Gaccount.CSTATACT = '003' THEN 'BLOCKED '
END "ACCOUNT STATUS",
TO_CHAR(GCARD.DEXPICRD,'DD-MM-YYYY') AS "EXPIRY DATE" ,
case when GCARD.CUTYPCRD = '001' then 'PRIMARY '
     when GCARD.CUTYPCRD = '002' then 'AUTHORISED '
end "ACC TYPE"      
FROM GCARD,GACCOUNT,GRACTCRD,GPCSTMER
WHERE GCARD.NCRD = GRACTCRD.NCRD AND
GCARD.NBIN = GRACTCRD.NBIN AND
GACCOUNT.NACT = GRACTCRD.NACT AND
GACCOUNT.NBIN = GRACTCRD.NBIN AND
GCARD.CRSVLCRD = 000 and
Gaccount.CSTATACT = 000 and
GPCSTMER.NCST = GCARD.NCST AND
GCARD.NBIN IN (515869) AND
PAN_INDEX_RANGE_ID = 50
ORDER BY GCARD.DISSUCRD,gcard.ncrd,PAN_INDEX_RANGE_ID;
This my whole query and when i extract the information i have for the whole range.. but me i want to input for a specific date range

Similar Messages

  • BW 3.5 - How can I select TADIR objects in a specific date range?

    Hi everybody,
    I have the necessity to obtain a list of BW objects in a specific date range. I have observed that using TADIR table it is impossible because a timestamp is not present. I have also the necessity to group the BW objects using the object type of the TADIR table (e.g. PROG for Program).
    Any idea?
    Many thanks in advance for your kind support.
    Regards,
       Giovanni

    Hi Giovanni
    I would suggest you try put table TADIR in SE11 and generating a "Where-Used List (CtrlShiftF5)" Also you should try double click on data element SOBJ_NAME in the database view of TADIR and generate a Where-Used List on that field, then you can see the relationships of the table/field.
    I hope this works for you
    Good Luck
    Ben
    Please Assign Points if Useful

  • Count records for a specific date range

    Hi,
    I am using BI Publisher with Siebel 8.1.1.1. I have a monthly report where I want to count the number of service requests entered per customer per month.
    I am using the following expression that works for one month:
    <?count(ssServiceRequest[ssSeverity[.='1-Critical'] and xdoxslt:date_diff('d',psfn:getCanonicalDate(ssCreated), xdoxslt:current_date($_XDOLOCALE,$_XDOTIMEZONE), $_XDOLOCALE, $_XDOTIMEZONE) <=28])?>
    However, I want to be able to specify a specific date range for my count, i.e ssCreated >= '01/02/2011' and <= '28/02/2011', as opposed to count for the past 28 days. Can you please advise what syntax I can use to specify a date range?
    Any help will be greatly appreciated!
    Claire

    Hello,
    Many many thanks for your reply.
    I'm doing as you suggest and am using the date_diff to the end of the period in question. I've tried the following to get the number of Service Requests with Severity 1-Critical, created in Jan 2011, feb 2011:
    <?count(ssServiceRequest[ssSeverity[.='1-Critical'] and xdoxslt:date_diff('d', (psfn:getCanonicalDate(ssCreated), $_XDOLOCALE, $_XDOTIMEZONE), '2011-01-31', $_XDOLOCALE, $_XDOTIMEZONE) <=31])?>
    <?count(ssServiceRequest[ssSeverity[.='1-Critical'] and xdoxslt:date_diff('d', (psfn:getCanonicalDate(ssCreated), $_XDOLOCALE, $_XDOTIMEZONE), '2011-02-28', $_XDOLOCALE, $_XDOTIMEZONE) <=28])?>
    In my xml sample data that I'm using I have 2 service requests that mean the criteria for Jan, yet when I run my report I'm getting '0'. The problem seems to be with my end of period date '2011-01-31'. I've also tried with both start and end period date (using a negative value as per your suggestion), but I still get '0':
    <?count(ssServiceRequest[ssSeverity[.='1-Critical'] and xdoxslt:date_diff('d', (psfn:getCanonicalDate(ssCreated), $_XDOLOCALE, $_XDOTIMEZONE), '2011-01-01', $_XDOLOCALE, $_XDOTIMEZONE) <=-31 and xdoxslt:date_diff('d', (psfn:getCanonicalDate(ssCreated), $_XDOLOCALE, $_XDOTIMEZONE), '2011-01-31', $_XDOLOCALE, $_XDOTIMEZONE) <=31])?>
    Many thanks,
    Claire

  • Sync with Outlook ONLY for a specific date range

    I have a Zire 31 that I'm syncing with Outlook via latest Palm Desktop/HotSync.   I did just install the latest conduit.
    I was getting several repeating calendar entries that were not syncing with the Zire (annual birthdays, etc.) - turns out that they did not have an "end-date" specified when created in Outlook.  Creating an end-date solved the problem.
    However - I would like to know if it is possible to specify a certain date range for the device to sync (e.g., sync calendar only for years 2007 through 2050, or in other words sync from 1 year ago to 50 years in future, etc...)
    I recall specifying this once years ago, but I may have been using a third party to sync with Lotus Notes at the time.  I'm wondering if this option is also available with syncing directly with Outlook using HotSync???  I can't imagine it's not, but I can't find where you specify it.
    One more interesting note:  while my Zire 31 had issues syncing those repeating calendar entries - my much older HandSpring Visor Deluxe syncs them no problem!  Go figure.
    Thanks much -
    Post relates to: Zire 31

    I'm not actually looking to purge old items.
    Rather - I would like to ONLY sync calendar entries between a specified range of dates.  For example - ONLY sync for calendar entries between Jan 1 2007 and Jan 1, 2050.
    the problem is that I have some repeating entries (birthdays, etc.) that are set up in Outlook with no end date.  Apparently Palm/HotSync is having trouble syncing these (they don't show up at all - for any year.)
    One resolution is to apply an end-date for each repeating calendar entry.  However, this is just another step my wife needs to remember to do.  If you happen to forget to to this, then Hotsync will ignore that entry.  Fine if you realize that's happening, but if you forget and forget to check - you won't even know it didn't sync!
    The other possible resolution is to only have HotSync sync for a SPECIFIC date range - one that does not presumably go to infinity.  That is my question - how does one sync ONLY for a specific date range.  Has nothing to do with purging old entries.
    Thanks!!
    Post relates to: Zire 31

  • Deleting emails with in a specific date range

    Is there a way to delete a specific date range of email using 10.9.3 or Gmail. Thanks

    Try making a rule or a Smart mailbox to delete them.
    Rules, Smart Mailboxes, and VIPS

  • Ical searches with specific date range

    We post the people who are to work at specific events in the notes field of ical. Is there a way to search for these peoples names on the web via ical.php within a specific date range? No matter what date I have set to look at on the calendar the search grabs everything in the past. I only want future events that this person is associated with. Thanks for helping if you can. Jake

    Hi,
    You want to run the report on specific date without 0CALDAY?. Without 0CALDAY you can't restrict the report for specific day. So you must insert 0CALDAY in report and then use Offsets or implement code in CMOD.
    Thanks
    Reddy

  • Issue with displaying QM control chart for specific date range

    Dear All
    In our chemical mfg organisation, we just implemented SAP QM solution and things are working fine. I have implemented control  chart functionalities as below:
    SPC Criteria in Inspection Plan: Task List Charateristics / Material (0020)
    Sampling Procedure: Fixed Sample / SPC Inspection (without inspection point)
    We use process orders to get the inspection lots for products (material) and record results for the MICs and UD the inspection lots.
    Currently all our Control Chart have status 1 (created) and we have not moved any of those charts to status 3 and 5 yet.
    Using QGC1 when user trying to run control chart for any particular material in the plant and for a specific date range, report showing all the charts for that material with different MICs as expected. Though the result is NOT restricted to the selection dates either against "Lot Created On" or " Insp. Start Date" ( may be due to SPC criteria????) , its always showing all the result for any particular MIC for that material starting from go live till today.
    How to restrict the dispaly of result on the chart for any particular MIC against the Material / Plant within a specific date range ?
    Looking forward for your response.
    Best Regards
    SK

    Hi,
    1. Even though when i give the Created on, and to date the system is displaying the report which is prior to the created on date.
    2. Similarly the report data is different when the field is maximum no of Hits is given. for example when i giving this field as 10, 20, 30, etc the report is showing only 10 line items. if i enter 50, 60 etc it is showing the list for half i given.
    Note that system is having more than 1000 line items to display..
    Regards,
    R. Loganathan

  • How to get the weekends days for a specific date range

    I want to select list of only weekend dates from a given date range. Is it possible in SQL?
    For example if the range is '08/01/2011' and '08/30/2011'
    I want a list
    08/06/2011
    08/07/2011
    08/13/2011
    08/14/2011
    08/20/2011
    08/21/2011
    08/27/2011
    08/28/2011Thank You, Naveen email:[email protected]

    First and easy to do is having a Calendar table, which over there you can have those information.
    http://arbibaghdanian.blogspot.com/2011/05/calendar-table.html
    Declare @beginDate Date, @EndDate Date
    Select @beginDate = '08/01/2011', @EndDate = '08/31/2011'
    Declare @Calendar Table
    (CalendarDate Date Primary key, IsWeekend Bit, YearNo SmallInt, QuarterNo TinyInt, MonthNo TinyInt, DayOfYearNo SmallInt, DayNo TinyInt, WeekNo TinyInt, WeekDayNo TinyInt)
    While @beginDate <= @endDate
    Begin
    Insert Into @Calendar
    Select
    @beginDate As CalendarDate
    ,(Case When DATEPART(Weekday, @beginDate) In (7, 1) Then 1 Else 0 End) As IsWeekend
    ,DATEPART(Year, @beginDate) As YearNo
    ,DATEPART(QUARTER, @beginDate) As QuarterNo
    ,DATEPART(MONTH, @beginDate) As MonthNo
    ,DATEPART(DayOfYear, @beginDate) As DayOfYearNo
    ,DATEPART(Day, @beginDate) As DayNo
    ,DATEPART(Week, @beginDate) As WeekNo
    ,DATEPART(WEEKDAY, @beginDate) As WeekDayNo
    Set @beginDate = DateAdd(Day, 1, @beginDate)
    End
    Select * From @Calendar Where IsWeekend = 1
    Best Wishes, Arbi --- MCC 2011; Please vote if you find this posting was helpful or Mark it as answered.

  • How to get a date range in JDBC sql

    I am using the following in my sql to get a date range... but what if the field is a timestamp will that still work or not...
    AND a.date>=? AND a.date<=?

    Suzie,
    No offence, but is there something stopping you from testing it yourself?
    Good Luck,
    Avi.

  • Pass date range parameter  to SQL stored procedure.

    Hi,
    I'd like to pass a date range parameter from Crystal Reports to a sql stored procedure. Does anyone know if this is possible?
    I've had no problem passing standard datetime (single value) paramaters to and from but am struggling with getting a range value parameter to work.
    Environment: Crystal Reports 10/XI and SQL 2000 MSDE version or SQL 2005 Express Edition.
    Any help would be appreciated.

    C5112736 wrote:>
    > And then these 2 formulas 'Formula # 1' and 'Formula # 2' can be used to pass on to the stored procedure.
    Can someone please demonstrate exactly how to use formula results as date parameters to a SQL stored procedure?  Keep in mind, there are two parameters to the stored procedure.
    I have gleaned this much: Use Add Command and insert the procedure with
    EXEC ServerName.dbo.usp_sprocName;1 '{?StringParameter}'
    but if I try to do
    {CALL ServerName.dbo.usp_SprocName({@Formula1},{@Formula2})}
    then it gives the error "No value given for one or more required parameters". 
    Both of the parameters are VARCHAR(50).
    I have finally found this link: [http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx|http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx]
    This Microsoft site defines the format of the ODBC escape sequences, but I still do not know how to convince Crystal to insert it's parameter results or formula results.
    Pulling what's left of my hair out . . .
    ~ Shaun

  • Exporting iCal events in a specific date range

    Is this  possible?  I want to export events from one calendar, but only in a certain date range, to give to another user to import into their iCal calendar...

    Try making a rule or a Smart mailbox to delete them.
    Rules, Smart Mailboxes, and VIPS

  • How to see Control chart for a specific date range in QGC3

    Hi
    I am developing SPC for my client.I am facing one problem.
    I am using one control chart for all inspection lot for a particular MIC.Free inspection point is used in inspection plan.
    Control chart is used 516.(XMR chart)
    Now when i am calling control chart for MIC executing QGC3,chart is showing results since creation chart date to todays date.
    Now if i want to see chart for a particular period or date range,what is the procedure.
    Thanks in advance
    Nilanjan

    Hi,
    1. Even though when i give the Created on, and to date the system is displaying the report which is prior to the created on date.
    2. Similarly the report data is different when the field is maximum no of Hits is given. for example when i giving this field as 10, 20, 30, etc the report is showing only 10 line items. if i enter 50, 60 etc it is showing the list for half i given.
    Note that system is having more than 1000 line items to display..
    Regards,
    R. Loganathan

  • Data server switch in SQL query

    Hi guys,
    I have a question about data server switch in the sql query template. We have been developing all the sql queris pointing to the customer test db server say "TESTDB", now we have to change the db connection to "PRODUCTDB", do we need to change sql queries one by one or is there a better solution for this? I think this is a common requirement to change back and forth data server connection for a bulk number of queries
    Thanks,
    Tony.

    Tony,
    From a design perspective it is advisible to name your data servers in a more abstract way, since the query templates themselves only save the Name of the data server in them.  Data Servers also have a description field (typically overlooked) which will appear in the list and the workbench where you can be explicit or to even serve as a reminder that you are working with either test or production data.  The true 'switch' should happen when you reconfigure your data server settings for server url and user/pwd.
    TESTDB and PRODUCTDB might be better served with a meaningful name that provides a correlation to the data stored in the database.  In more mature system landscapes having a DEV/QA/PROD arrangement of MII servers, the ability to promote content comes from configuration and projects, not from actually changing the content on the same server.
    If you need to rapidly modify your content to adopt this practice then I would simply export the associated project and unzip it to a folder.  Then use windows explorer to do a search for files containing your data server name (they will appear in your query templates as Server="TESTDB").  With a text editor that can do search and replaces across multiple files (http://www.editplus.com is my personal favorite) you can easily change the data server name to a better convention.  Then zip up the folder content and reimport the project.  This will effectively switch your data servers (don't forget to create the new abstract data server in place of the TESTDB and PRODUCTDB).
    Regards,
    Jeremy

  • Dynamic date range creation for WebI query

    Hi
    I have a webi query where I need to provide a date range as selection.  But the from date will be based on number of days that user will provide during query execution. For e.g. user will give no of days as 10 so the date range need to be created as  (system date -10) to (system date).
    I am not sure how to provide the option for user to input no of days and then calculate the date range.
    Could you please help me here.
    Regards,
    Amit

    Amit.
    it can be done but by creating multiple objects.
    create Obj1: @prompt("Enter Number Of days",N,Mono,etc..) and capture the number of days in it.
    Create your second object infact a filter object: Obj2: Sysdate
    Third Object(filter) Obj3:  (Sysdate-(@select(class\Obj1)))
    give the between condition in webi using these two objects
    between Obj2 and Obj3

  • Return default data if no data is returned by sql query

    Hi,
    I have a requirement.
    I have an inner query that returns no data. However I still want to return default data (say 'abc'). The below sql does not return anything inspite of using nvl . Please advise .
    select nvl( x.vencode,'abc') vencode
    from
    -- below sql returns no data!
              SELECT a.vencode vencode,
                     a.mid mid,
                     a.title title,
                      ROW_NUMBER() OVER (PARTITION BY a.vencode ORDER BY a.title) rnk
               FROM (
                     SELECT *
                     FROM    (SELECT vencode FROM vendor where login is not null and vencode = 'BKFI'
                                        and login > (sysdate - 90) )
                          CROSS JOIN
                             (SELECT mid, title, ROWNUM num FROM tcommmemos where mid is not null)
                    ) a,        
                   (SELECT * FROM (
                    SELECT v.vencode, tc.mid, tc.title
               FROM
               (select  * from vendor
                     where login is not null and vencode = 'BKFI'
                     and login > (sysdate - 90)) v,
                tcommmemosviewed tcv, tcommmemos tc
               WHERE     v.vencode = tcv.vencode
                     and tc.mid is not null
                     --AND tc.post_date > v.hiredate
                     AND tc.mid = tcv.mid)
                   ) b
                   where a.vencode = b.vencode(+)
                     and a.title   = b.title(+)
                     and a.mid     = b.mid(+)
                     and b.mid is null                               
    ) x              

    Use any aggregate function it'll always return a value even if there no data in the table
    create table r_dummy_1 (a number);
    SQL> select * from r_dummy_1;
    no rows selected
    SQL> select nvl(max(a),1) from r_dummy_1;
    NVL(MAX(A),1)
    1

Maybe you are looking for