Greater than in a DECODE function

Hi,
Can anybody help?
I need to convert the following pseudo code into sql format:
if the difference between interview date and entered date is less than 10 days
then count the number students within the 10 days
else count the number of students who exceed the 10 days
I have tried using the CASE format but this just produced of list of 'within' and 'exceeds'
SELECT CASE WHEN to_date(idc, 'dd-mon-yyyy') - to_date(edc, 'dd-mon-yyyy') BETWEEN 0 AND 10 THEN 'WITHIN' ELSE 'EXCEED' END
Anyone got any ideas?
Thanks Jen

As SK says, your requirement is a slightly confusing. My assumption is that you want to do two counts, one for students within the bounds and one for students who exceed the bounds. Well you can do that like this:
SELECT sum(CASE WHEN to_date(idc, 'dd-mon-yyyy') - to_date(edc, 'dd-mon-yyyy') BETWEEN 0 AND 10 THEN 1 ELSE 0 END) WITHIN
       , sum(CASE WHEN to_date(idc, 'dd-mon-yyyy') - to_date(edc, 'dd-mon-yyyy') > 10 THEN 0 ELSE 1 END) EXCEEDs
FROM your_tableRas malai, APC

Similar Messages

  • Less than or greater than Decode Function

    Can we use less than or greater than (relational operator) operator in decode function

    Use Case instead.
    Not sure if you need it in your resultset or your where clause.
    Simple examples:
    MHO%xe> with numbers as(
      2  select 1 a, 3 b from dual union all
      3  select 2 a, 3 b from dual union all
      4  select 3 a, 3 b from dual union all
      5  select 4 a, 3 b from dual union all
      6  select 5 a, 3 b from dual
      7  )
      8  select 'QRY1'
      9  ,      a
    10  ,      b  
    11  from   numbers
    12  where (case when a >= b then 1 end) = 1
    13  union all
    14  select 'QRY2'
    15  ,      case when a < b then b else 0 end
    16  ,      case when b < a then a else 0 end
    17  from numbers;
    'QRY          A          B
    QRY1          3          3
    QRY1          4          3
    QRY1          5          3
    QRY2          3          0
    QRY2          3          0
    QRY2          0          0
    QRY2          0          4
    QRY2          0          5

  • Greater than function not sourcing bool?

    HI, I have the following.
    Whenever I try to connect the 'Greater than' output to the AND function I keep getting a connection error "Dynamic type not Bool" well something like that. If this is the case how come I was allowed to connect the 'Less than' function to the AND?

    I don't use dynamic data either, but in your case you could use the limit testing express VI.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Expresslimits.PNG ‏5 KB

  • Greater Than Function in Script Logic File

    BPC Experts,
    I've got a pretty simple script logic file to calculate salary amounts, overtime, etc.  The purpose of this logic is for forecasting.  I have two referenced dimensions, TIME and SCENARIO, where TIME.MONTHNUM is equal to its relative month number (eg: Jan monthnum = 1), and SCENARIO.CURRMONTH is equal to the relative amount of actual months data, (eg Jan currmonth = 0, Feb = 1) because if you are completing a February forecast, you have one month of actual.
    The ACTUAL scenario is never touched, but after a month closes, we copy the ACTUAL data to, for example, FEB_FCST.  So, after January closes, its actuals are copied to the FEB_FCST scenario so we can complete an actual/forecast (one month actual, 11 months forecast).
    Currently, the default logic skips anything in the ACTUAL scenario, by stating "*WHEN SCENARIO, *IS <> "ACTUAL" yada yada yada.
    However, when the default logic runs on the forecast scenarios, it takes the same inputs from the months that are copied over from the ACTUAL scenario and adds to the original amount, essentially doubling the value--ultimately causing an incorrect actuals number in the forecast scenario.
    My script right now looks like this:
    *XDIM_MEMBERSET DATASRC=INPUT
    *XDIM_MEMBERSET PRODUCT=NO_PRODUCT
    *XDIM_MEMBERSET SHIFT=NO_SHIFTS
    *XDIM_MEMBERSET MEASURES=PERIODIC
    *WHEN SCENARIO
    *IS <> "ACTUAL"
         *WHEN TIME.MONTHNUM
         *IS > SCENARIO.CURRENTMNTH
              *WHEN ACCOUNT
              *IS "SALARIED_MANPOWER"
                   *REC(EXPRESSION=((([ACCOUNT].[SALARIED_AVG_WAGE] * (1 + [ACCOUNT].[SALARY_TIMEAHALF]))* [ACCOUNT].[SALARIED_MANPOWER])),ACCOUNT="01100")
              *ENDWHEN
    *ENDWHEN
    *ENDWHEN
    *COMMIT
    When it hits line 9 (*IS > SCENARIO.CURRENTMNTH) during validation, it errors.  How can I use a "greater than" function to dictate whether or not a given scenario should run default logic on a specific month?
    If not, is there a different/better way to do it?
    Thank you!
    ABF

    Hi Alex
    Take this sample logic, check the properties in your Time dimension to trouble shoot your issue.
    *SELECT(%CAT_VAR%, "ID", CATEGORY, ID= PLAN_APRIL)
    *XDIM_MEMBERSET CATEGORY = ACTUAL, PLAN, %CAT_VAR%
    *SELECT(%CATMTH%, "STARTMTH", CATEGORY, ID= %CAT_VAR%)
    *SELECT(%ACT_PERIOD%, "ID", TIME, MONTHNUM < %CATMTH% AND  LEVEL = MONTH AND YEAR = 2010)
    *SELECT(%PLAN_PERIOD%, "ID", TIME, MONTHNUM >= %CATMTH% AND LEVEL = MONTH AND YEAR = 2010)
    *XDIM_MEMBERSET TIME= %ACT_PERIOD%
    *XDIM_MEMBERSET CATEGORY=ACTUAL
    *WHEN CATEGORY
    *IS ACTUAL
    *REC(EXPRESSION=%VALUE%, CATEGORY = %CAT_VAR%)
    *ENDWHEN
    *XDIM_MEMBERSET TIME= %PLAN_PERIOD%
    *XDIM_MEMBERSET CATEGORY=PLAN
    *WHEN CATEGORY
    *IS PLAN
    *REC(EXPRESSION=%VALUE%, CATEGORY = %CAT_VAR%)
    *ENDWHEN
    Thanks

  • I have a manual that contains headings and index entries that contain less than and greater than characters, and . The Publish to Responsive HTML5 function escapes these correctly in the main body of the text but does not work correctly in either the C

    I have a manual that contains headings and index entries that contain less than and greater than characters, < and >. The Publish to Responsive HTML5 function escapes these correctly in the main body of the text but does not work correctly in either the Contents or the Index of the generated HTML. In the Contents the words are completely missing and in the index entries the '\' characters that are required in the markers remain in the entry but the leading less than symbol and the first character of the word is deleted; hence what should appear as <dataseries> appears as \ataseries\>. I believe this is a FMv12 bug. Has anyone else experienced this? Is the FM team aware and working on a fix. Any suggestions for a workaround?

    The Index issue is more complicated since in order to get the < and > into the index requires the entry itself to be escaped. So, in order to index '<x2settings>' you have to key '\<x2settings\>'. Looking at the generated index entry in the .js file we see '<key name=\"\\2settings\\&gt;\">. This is a bit of a mess and produces an index entry of '\2settings\>'. This ought to be '<key name=\"&amp;lt;x2settings&amp;gt;\" >'. I have tested this fix and it works - but the worst of it is that the first character of the index entry has been stripped out. Consequently I cannot fix this with a few global changes - and I have a lot of index entries of this type. I'm looking forward to a response to this since I cannot publish this document in its current state.  

  • Numbers function IF greater than using date & time

    I am trying to produce a number sheet that will allow me calculate a working rota for staff.
    The problem i am having is when i try and use a IF function to remove 1hr (for lunch) if the person works 8 hours or more.
    If that person works between 6 and 8 they require a 30 mins lunch.
    I have already setup the sheet to calculate the total shift time by subtracting the starting time from the finishing time. i.e. 18:00 - 08:00 = 10hrs
    Now i need it to subtract 1hr for lunch.
    It should read something like IF 10 >8 then -1 from 10.
    I just don't know how to not cause an error.
    ideally i would like it to be able to handle 2 IF's in the one cell. if its 6-8hrs - 30mins or if its greater than 7 -1 hr.
    I currently have all the cells set at time and date.
    Any help would be greatly appreciated.
    Richard

    this works a little but it seems to subtract 0.5 and then 1 removing to much time.
    I have attached a link which i hope will explain this better.
    https://onedrive.live.com/redir?resid=82B56CEF9A61CDE9!8770&authkey=!ALJn-lja2b2 q1iw&ithint=file%2cnumbers
    Thank you for your help

  • How can a function returning character length greater than 4000 be selected in SQL

    Hi,
    I want to know if there is a way to write a select query on a function call which returns a varchar of more than 4000 characters.
    CREATE OR REPLACE FUNCTION FUNC1
    RETURN VARCHAR2
    IS
    str VARCHAR2(32767);
    BEGIN
         str := <some string greater than 4000 char>;
          RETURN str;
    END;
    SELECT FUNC1 from dual; ---- This gives an PL/SQL numeric or value error. Character string buffer too small.
    Is there any way to resolve this?
    Thanks

    32767 is not default. The default is still 4000 for VARCHAR2. You need to set the initialization parameter MAX_STRING_SIZE= EXTENDED for 32767.
    Text from Oracle documentation
    Extended Data Types
    Beginning with Oracle Database 12c, you can specify a maximum size of 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types. You can control whether your database supports this new maximum size by setting the initialization parameter MAX_STRING_SIZE as follows:
    If MAX_STRING_SIZE = STANDARD, then the size limits for releases prior to Oracle Database 12c apply: 4000 bytes for the VARCHAR2 and NVARCHAR2 data types, and 2000 bytes for the RAW data type. This is the default.
    If MAX_STRING_SIZE = EXTENDED, then the size limit is 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types.

  • Why domain functional level should be greater than or equal to forest FL?

    We know that domain functional level must be greater than or equal to forest functional level. Why is that so?
    My perspective is if we set FFL to windows server 2008 r2 and DFL to windows 2003, active directory recycle bin won't be available to the domain whose FL is windows 2003. Is that right?

    My perspective is if we set FFL to windows server 2008 r2 and DFL to windows 2003, active directory recycle bin won't be available to the domain whose FL is windows 2003. Is that right?
    Greetings!
    Active Directory Recycle Bin needs to be implemented in a forest with 2008 R2 forest functional level. Because it was added in 2008 R2 operating system. In order to have a 2008 R2 forest functional level you need to raise all the child domains DFL's first.
    Regards.
    Mahdi Tehrani   |  
      |  
    www.mahditehrani.ir
    Please click on Propose As Answer or to mark this post as
    and helpful for other people.
    This posting is provided AS-IS with no warranties, and confers no rights.
    How to query members of 'Local Administrators' group in all computers?

  • Decode function--urgent

    hai all,
    this is the query from robinson .....
    I am trying to use decode function as below in PL/SQl..
    DECODE(column1,a1,1,a2,2,a3,3,......a150,150,null)
    i got a error as
    ---unhandled exception---
    If this decode function is restricted to 120 values i get the
    answer.
    so i would like to know whether there is any restriction for the
    number of arguments to be passed to the decode function.
    I will be glad and grateful to receive a answer...for this query.
    thanks in advance...
    robinson

    I'm not sure what is the limit for the decode function
    arguments, but it certainly seems that you've reached it.
    So, I'd recommend that you write a stored function that you will
    call in your select. It should be like the following:
    create
    function f_decode (p in your_data_type) return your_ret_type
    is
    begin
    if p=expr1 then
    return value1;
    elsif p=expr2 then
    return value2;
    elsif p=exprn then
    return exprn;
    else
    return def_value;
    end if;
    Or, another way to handle it, even more graciously when the
    number of possible values will vary pretty often may be to have
    a table that you would join.
    That's what I do when a have to deal with more than 10-20 values.
    end;

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Unit Testing  - Results greater than 0

    I am unit testing a PL/SQL function. The function has no inputs and one output (Interval Day to Second) . The output is the time it takes to run a query therefore a valid value for the output would be greater than 0.
    When I setup the test the result only takes a Interval Day to Second value. I want to be able to say any result greater than 0 is a success.
    How can I do this?
    tom

    I am unit testing a PL/SQL function. The function has no inputs and one output (Interval Day to Second) . The output is the time it takes to run a query therefore a valid value for the output would be greater than 0.
    When I setup the test the result only takes a Interval Day to Second value. I want to be able to say any result greater than 0 is a success.
    How can I do this?
    tom

  • Schedule line getting confirmed when Ordered Quanity is greater than stock.

    Hi Sap Gurus,
    We have an issue in one of the sales scenario.
    In one of the sales orders the ordered quanity is purposely maintained greater than the stock at respective storage location(batch managed).
    In this case the schedule line should not get confirmed and it should not allow delivery document creation.
    But in the sales order the schedule lines are geeting confirmed and even the delivery document is getting created with picking request completion.
    Could you please help to understand :
    1.  why the schedule lines are getting confirmed when ordered quantity > Inventory?
    2. How do I stop delivery document creaton in this scenario?
    Looking for a quick response.
    Thanks in advance,
    Bhaskar

    Hello Bhaskar,
    Is Availability Check in your system considering Replenishment Lead time, if yes, then this is possible.
    Check this IMG Link:
    IMG - Sales and Distribution - Basic Functions - Availability Check and Transfer of Requirements - Availability Check with ATP Logic or Against Planning - Carry Out Control For Availability Check
    Here check the RLT settings.
    Also check settings under In/Outward Movements, where things like include Purchase Order can lead to confirmation of stock in Sales Order, despite physical inventory being present.
    Hope this helps,
    Thanks,
    Jignesh Mehta

  • PO greater than Shopping Cart Qty

    Friends,
    We are working on extended classic scenario where PO is created as follow-on document from shopping cart. User can create PO in sourcing cockpit using Process PO option. However here user has the option to change PO qty where system accepts PO qty greater than SC qty. We would like to restrict it.
    In R/3 MM we can control this via system message and restrict PO qty to exceed PR qty.
    How can we control this functionality in SRM?
    Regards,
    Sandeep Parab

    Hi. Try the BBP_DOC_CHECK_BADI.
    You should be able to check the quantities and issue an error if the quantity has been changed.
    Regards,
    Dave.

  • Decode function involving 2 fields (urgent)

    Hi .. I am trying to use the decode function involving 2 fields.
    The query runs but does not produce the correct results. If
    anyone knows, please reply .. Usually decode function involves
    one column only but I have more
    than one. The situation is : If ins_code = 2 or special_code =
    MMI, put a 'Y', otherwise, it's a 'N'. Does anyone know how to
    put this in a decode statement? Thanks

    Thanks, Suresh ... but I have to put this condition using the
    decode statement because that's how the rest of the program is
    written. It's part of the script that I have to change. The
    current statement is this: decode(ins_code, '2', 'Y', 'N'). I
    have to change it to ins_code =2 or special_feature = MMI.
    Please reply ... thanks a lot....

  • GREATER THAN symbol appearing as &gt ; in SQL*Plus

    Version:11.2.0.3
    OS : RHEL 5.4
    We are a Software vedor firm.We have sent our SQL files to our client to execute. But the codes for various procedures and functions were failing
    because, in their SQL*Plus session (in Putty) the LESS THAN character < was appearing as &lt ; and GREATER THAN character > was appearing as &gt ;
    In the original code which we had sent to them has no problems with > or < characters.
    Original code
    Cursor feb_cur IS
      SELECT user_pwid
        FROM carton_hdr_dtl
       WHERE MODIFIED_DATE >= D_Last_Run_Date
       UNION
      SELECT user_pwid
        FROM carton_hdr_dtl_bkp
       WHERE (modified_date >= D_Last_Run_Date OR
              deleted_date >= D_Last_Run_Date);  But in the execution log file sent by our client, I can see &gt ; instead of > character.
    54   Cursor feb_cur IS
    55    SELECT user_pwid
    56        FROM carton_hdr_dtl
    57       WHERE MODIFIED_DATE &gt ;= D_Last_Run_Date
    58       UNION
    59    SELECT user_pwid
    60        FROM carton_hdr_dtl_bkp
    61       WHERE (modified_date &gt ;= D_Last_Run_Date OR
    62              deleted_date &gt;= D_Last_Run_Date);What are they doing wrong? They use putty. We use putty too but we don't have any issues.
    Edited by: Max on Dec 17, 2012 2:42 AM

    Thank you Blushadow, Nicosa for providing this clue.
    I checked with my client. They have put our scripts in Collabnet SVN version control and the implementor DBA will be provided the http URL .
    Apparently SVN is accessed using http protocol and yes you are right it is opened through a browser by typing an URL like below
    http://10.80.16.214:79839/svn/brcf/DBfiles/2012/WMHReleasel8/hrtb_pkt_wave.sqlFor most of the end users , the GREATER THAN character appears as > without any issues . For some users it appears as &gt ; . One potential cause is the difference in Internet Explorer version. They are currently looking into this.
    THANK YOU BLUSHADOW and NICOSA for shedding light on this.
    Hi Nicosa,
    A forum formatting question:
    How did you manage to get &gt_; (without the underscore) printed ? When I tried it the forums editor was converting it to > . This is why I placed a space/underscore between t and semi colon. Is there some escape character ?

Maybe you are looking for

  • Exporting a PDF with a playable QuickTime embedded

    Is it possible? Thanks

  • DNS forwarder with 2 real DNS servers, querying them simultaneously

    DNS forwarder with >2 real DNS servers, querying them simultaneously and ignoring "server can't find" errors Hi. When I connect to VPN, my normal DNS isnt queried, and DNS given by VPN answers: "server can't find" An extract from 'man resolv.conf' If

  • Stroke command not available

    I am trying to add an outline to a dialog bubble. I can't figure out how to make the Stroke Command available. It is greyed out. I have tried to select the layer, tried everything. What am I missing? Thanks. nancy

  • Characteristic Name of Sales Employee in COPA report is not appear

    Characteristic Name of Sales Employee in COPA report is not appear, it is just the a Code of Sales Employee 1.I created Characteristic Derivation t.code KEDR Table lookup PA0001 using condition Origin GLOBAL USERTEMP1 until USERTEMP6 2.During Test An

  • End Call + Answer

    When you are on a call and another call comes in the choices it gives are "Ignore" call & "Hold Call + Answer." Most of the time I just want to end the call I am on & answer the new call. Why does it give such screwy options?