Sql greatest,decode,instr.  minimize code lines sql

I did not write this code and please excuse me for my
beginner questions?
· Is there a way to make this code cleaner. Code it
where its less lines of code?
· Can we make the 2 conditions separate rather than a
one after the other?
For ex. Not like this WHEN
INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
· why is it in a pair like this:
WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
if the string to find in
CASESTAB_1.CASENOTXT is independent to comparing date?
Can the string search and date be separate?
· Is the a shorter way of comparing the 4 dates.?
Alternatives
Greatest(
CASE
WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
WHEN INSTR(CASESTAB_1.CASENOTXT,'-ss’) > 0 THEN
decode(ERTAB.FINERDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.FINERDT)
WHEN INSTR(CASESTAB_1.CASENOTXT,'-dd ') > 0 THEN
decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLICATIONDT)
WHEN INSTR(CASESTAB_1.CASENOTXT,'-ff’) > 0 THEN
decode(ERTAB.PUBLICATIONDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),ERTAB.PUBLICATIONDT)
ELSE
decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT)
END
,decode(CASESTAB.CPDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB.CPDT))
sql finds the suffixes from CASESTAB_1.CASENOTXT
AND
compares dates 4
· CASESTAB_1.RECDT
· ERTAB.FINERDT
· ERTAB.PUBLICATIONDT
· CASESTAB.CPDT
AND GETS THE LATER OF THE 4 DATES.
1. \find the suffix from caseN0 field/col
-ll
--ss
-dd
-ff
CASESTAB_1.CASENOTXT
2. dates to find the latest date.
· CASESTAB_1.RECDT
· ERTAB.FINERDT
· ERTAB.PUBLICATIONDT
· CASESTAB.CPDT
Using greatest function.
3. the tables are
1. ERTAB
2. CASESTAB
3. CASESTAB

Well, I don't know how much simpler it could get and still do
what it is designed to do. For example, the statement
WHEN INSTR(CASESTAB_1.CASENOTXT,'-ll’) > 0 THEN
decode(CASESTAB_1.RECDT,NULL,TO_DATE('01/01/1900','mm/dd/yyyy'),CASESTAB_1.RECDT)
basically means that if the CASENOTXT column contains
'-ll’, then look at the RECDT column and if it is NULL, use
the date value of '01/01/1900', otherwise use the date value in the
RECDT column.....
and so on through the other WHEN clauses in your CASE
statement. Is this what you are expecting thsi query to do?
Phil

Similar Messages

  • CASE..WHEN &a THEN decode(instr(colA,'-') 1,colA,......

    Using CASE within a function I wish to apply a second level of criteria within the CASE statement, something along the lines of the following:
    CASE upper(option_in)
    WHEN 'P' THEN decode(instr(value_in,'-')>1,value_in,plan_b)
    WHEN ...
    Looks nifty but doesn't work. Any suggestions would be appreciated.
    Thanks,
    Dan

    Why are you switching to DECODE? Just use CASE again:
    case upper(option_in)
    when 'P' then case
                  when instr(value_in, '-') > 1 then value_in
                  else plan_b
                  end
    when ...

  • [Goods Receipt PO - Rows - Tax Code][line: 1]

    Dear All,
            At the time of opening GRPO and Delivery Document suddenly system giving one error Number was used up in this sequence [Message 80071-20]
            And after it I entering required data in GRPO with any tax code then system giving new error [Goods Receipt PO - Rows - Tax Code][line: 1] , 'Internal error (-5) occurred'  [Message 131-183]
            I had verified that tax code which is selected in above GRPO is correct.
            When I try to Add GRPO without Tax code then different error coming Internal error (-5) occurred  [Message 131-183]
    Thanks,
    Siddique Shaikh

    Dear Gordon,
             Thanks for reply, I had setup the different sequence for all documents separately, But currently user using manual numbering option in Delivery and A/R Invoice Documents
             I checked new think is that system giving me same error only when we opening form which is creating financial JE in Backhand, Means when I opening Purchase Order or Sales Order form then system not giving any error and we can save PO or SO
            System is not allowing anybody to add any document which create financial effect.
    Thanks,
    Siddique.

  • XML Publisher and Graph code line limited

    Hi All,
    One of our graph report, seem have limited code line. The way we put the coding is in "right click on the graph" > Properties > Alt Tab.. Is there any others place that we can put the code for the graph generation?

    Hi All,
    One of our graph report, seem have limited code line. The way we put the coding is in "right click on the graph" > Properties > Alt Tab.. Is there any others place that we can put the code for the graph generation?

  • Table for tax code line item after miro

    Can anybody tell table for tax code line item (other than BSET) after MIRO.
    Raj

    Hi,
    First let me explain you the logic in this repot. 
    If a document have more than one GL accounts relevant for tax and having the same tax code. So there is only one tax line for that tax code in BSET.
    Now in the standard reports like S_ALR_87012357, output has the tax base amount etc, based on tax line from BSET which is a single line the above document. However this single line contains multiple tax relevant account and thus SAP can not show all the G/L account for this single line in the report S_ALR_87012357. So SAP picks up the first account in the output.
    The declaration in this report is not wrong, as the total gets calculated based on the tax code and which is correct and meets the tax reporting requirement.
    If you want to see the G/L account wise output, you can use the program RFUMSV10. Refer OSS note 1175418 "RFUMSV00: G/L account display" for details.
    https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=1175418
    In your report, you can use this program logic for reference.
    Regards,
    Gaurav

  • How I activate, when in code view current code line, to be highlighted (all line) eg light-blue ?

    How I activate, when in code view current code line, to be
    highlighted (all line) eg light-blue ?

    Actually, in Windows (XP) the highlight color (in DW8) is a
    byproduct of the
    color scheme you set for your desktop.
    Walt
    "Michael" <[email protected]> wrote in message
    news:gn7fpk$hbp$[email protected]..
    > In code view, click the line number in the left margin
    corresponding to
    > the line of code you wish to highlight. Left click that
    number and the
    > whole line will be highlighted in blue.
    >
    > Michael
    >

  • Execute a code line by line

    Hi, everyone
    according to you, what is the smartest way to execute a code line by line?
    Imagine the following situation : i got the following code:
    System.out.println("1");
    System.out.println("2");
    System.out.println("3");
    I got a GUI with a simple button "Execute next instruction" and a TextField ; each time the button is pressed, the next println is executed, so as the first click let appear a "1" in the textfield, the second click a "2", and the third one a "3"
    Ideas? Suggestions?
    Thanks in advance

    finally i did something like this:
    public class Example1 extends DebuggableCode {
        Memory mem = new Memory();
        Variable i, pi;
        @override
        public String getCCode() {
              return "int i = 10 ; \n int*pi = &i; \n *pi = 12; \n";
        @override
        public void execute() {
             switch (this.currentInstruction) {
                   case 0 : mem.add(i = new Int(10), Memory.STACK); break;
                   case 1 : mem.add((pi = new IntPointer(mem.getAddressOf(i)), Memory.STACK); break;
                   etc.
             this.fireMemoryChanged();
             this.currentInstruction++;
    }this way, the c code is first translated into java instructions with a mini framework to represent memory allocation, usage, etc, and then executed line by line with each new call to execute()
    don't think if it's a really good solution but i think it may work (not yet implemented)
    Edited by: calvino_ind on Jan 21, 2008 3:19 PM

  • Single Dev Environment and Code Line for 6 and CC?

    Hi All,
    Up until now, we were developing for customers who only used InDesign CS5.5 and CS6 - using Extension Builder 2.1.
    The problem is that now a new customer only has CC 2014.1 (they just purchased it today). I found one hack how to create an Extension using 2.1 for CC 2014/2014.1. However, this hack doesn't support HostAdapters, which we require as we want to control the fly panel of the panel menu.
    Also, I think CC 2014.1 supports only HTML5 panels. Does that mean a total re-write of all our code? And since CS6 does not support HTML5 panels - do we now have to maintain 2 parallel code lines until the last of our customers migrates to CC???
    I'd appreciate any advice.
    Regards,
    mlavie

    Hi mlavie,
    You're no need to rewrite tens of thousands code.
    You are free to use any UI framework that suits your needs.
    As I understood, Adobe supporting only Photoshop HostAdapter in Extension builder 3 for now, so in any case, in my opinion, only HTML will not give a solution to your problem.
    Instead you can write your own "HostAdapter" using Adobe Illustrator CC 2014 SDK, and connect it with your (Flash/Flex)extension. (check samples with Notifiers, it will help)
    According to InDesign, It's strange, because everything works smoothly for me. Can you write more detailed about that?
    ps, sorry for bad English.
    Best Regards,
    Gegham

  • Use sql function decode with Zend code

    Hi,
    I need to use sql function DECODE() in a query for PHP Code. This query works well in sql*plus but PHP returns
    the following error message:
    Parse error: syntax error, unexpected T_STRING in C:\Program Files\Zend\Apache2\htdocs\Compta\compta2.php on line 16
    the query is :
    $query =
    'select substr(c.NUM,1 ,2) Compte ,
    c.designation , a.Periode
    ,decode(substr(c.NUM,1 ,1), '1',1, '2',1,'3',1,-1) cp_type ,
    sum(credit) - sum(debit) Montant
    from ecritures a, clients b, compte c
    where
    b.NUM (+) =a.NUM
    and a.DATEECRITURE between to_date(:debut, \'dd/mm/yy\') and to_date(:fin, \'dd/mm/yy\')
    and substr(a.num,1,2) =c.num
    group by substr(c.NUM,1 ,1), substr(c.NUM,1,2) , c.designation ,a.periode
    order by compte ';
    Can any one help me ???
    Thanks by advance
    nb: Iuse Zend 2.0

    Hi,
    You need to escape single quote mark:
    decode(substr(c.NUM,1 ,1), \'1\',1, \'2\',1,\'3\',1,-1) cp_type ,
    the same way you did for to_date:
    to_date(:debut, \'dd/mm/yy\')
    Regards,
    Paweł

  • How Can I Fix My Decode and Mod Code In The SQL

    I have the following SQL statement.
    SELECT BEG_SVC_DT, END_SVC_DT,
    DECODE((SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1),30,mod(trunc(months_between((to_date('20'||end_svc_dt,'YYYYMMDD')),BEG_SVC_DT)),12)+ 1,
    mod(trunc(months_between((to_date('20'||end_svc_dt,'YYYYMMDD')),BEG_SVC_DT)),12))
    FROM SVC_OCCURRENCES
    WHERE SUBSTR(END_SVC_DT,1,1) IN '0'
    AND SUBSTR(END_SVC_DT,5,2) NOT IN ('31')
    Now if the decode returns a value of '30' then 1 is added to the remainder using
    the MOD function otherwise the MOD function is used and 1 is not added which is
    alright.
    After a '1' is added to the remainder , a value of '1','2','3','4', '5','6','7','8','9','10','11','12' is obtained which is alright also.
    However I do not want a '12' to appear instead I want a '0' (zero) to appear. Can I do this in an SQL statement? Eventually I want to do this in a report.

    SELECT BEG_SVC_DT, END_SVC_DT ,
    DECODE(
    (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,5,2)+1),30,
    mod(trunc(months_between(add_months(to_date('20'||end_svc_dt,'YYYYMMDD'),1),to_date('20'||BEG_SVC_DT,'yyyymmdd'))),12),
    mod(trunc(months_between((to_date('20'||end_svc_dt,'YYYYMMDD')),to_date('20'||BEG_SVC_DT,'yyyymmdd'))),12))
    FROM SVC_OCCURRENCES
    WHERE SUBSTR(END_SVC_DT,1,1) IN '0'
    AND SUBSTR(END_SVC_DT,5,2) NOT IN ('31')
    Hope this Helps
    Stan

  • DECODE/INSTR based on QUERY for SUBSTRING

    I am trying to write a function that can take a STRING and perform a DECODE on it by doing an INSTR for a value from a TABLE.
    MYTABLE
    VALUES               
    22XXXXXMNTSTT_       
    72XXXXXMNTSTT_       
    26XXXXXMNTSTT_       
    22XXXXXMNTHRSG       
    32XXXXXMNTHRSG       
    62XXXXXMNTBC__  
    DECODE_LIST_TABLE    
    SEARCH_VAL    TRANSLATE
    MNTHRSG        306    
    MNTBC            336     
    MNTSTT            393   
    MNTWTR            364 
    I WANT BACK          
    393
    393
    393
    306
    336
    TRYING:
    SELECT VALUES, INSTR( VALUES, SELECT SEARCH_VAL FROM DECODE_LIST_TABLE)>0  THEN ( SELECT TRANSLATE  FROM DECODE_LIST_TABLE WHERE ???????? )          
    FROM MYTABLENot sure how to finish the WHERE and if this is even doable with the approach I am taking?
    ANy help, greatly appreciated.
    Miller

    this?
    SQL> ed
    Wrote file afiedt.buf
      1  WITH my_tab AS
      2    (SELECT  '72XXXXXMNTSTT_' val FROM dual
      3     UNION ALL
      4    SELECT   '26XXXXXMNTSTT_ '  FROM dual
      5     UNION ALL
      6    SELECT    '22XXXXXMNTHRSG '   FROM dual),
      7   list_tab AS
      8      (SELECT 'MNTHRSG' s_val, 306 tr  FROM dual
      9     UNION ALL
    10    SELECT  'MNTBC',  336   FROM dual
    11     UNION ALL
    12    SELECT  'MNTWTR', 364    FROM dual
    13    UNION ALL
    14    SELECT  'MNTSTT', 393   FROM dual)
    15  -------- end you data<<<<<<<<<<<<<<<<<<<------ ignore with clause that for sample data
    16  SELECT val,tr FROM my_tab,list_tab
    17* WHERE INSTR(val,s_val)>0
    SQL> /
    VAL                     TR
    22XXXXXMNTHRSG         306
    72XXXXXMNTSTT_         393
    26XXXXXMNTSTT_         393format
    Message was edited by:
    devmiral

  • How to count source code lines?

    Hi guys!
    I have a task to calculate total amount of lines of source code. The only way i have found out is to get report
    with read report prog into itab statement and get number of lines with describe itab lines num_of_lines.
    But in this way it is not possible to handle classes for example. Is it possible to count lines with SQL statement?

    Hi,
    try this report [https://wiki.sdn.sap.com/wiki/display/Snippets/SearchforStringsinABAPSourceCode].
    For counting the lines you specify a search string of
    The includes for classes can be specified by
    ZCL_XY*
    Best regards
    Thomas
    Edited by: Thomas Schulz on May 4, 2010 1:33 PM

  • Decode statement in Select line of a View Object Query

    I attempted to create a view object in expert mode with a customized query.
    The query had a decode statement in the select line of the query. The view
    object compiled correctly but gave an error when run.
    ex: select .... decode(CrpSchools.SCHOOLS_ID,null,CrpCustSchools.SCHOOL_NAME,CrpSchools.SCHOOL_NAME) SCHOOL_VALUE, ...
    from ....
    where ....
    The error was that school_value does not exist in the statement. I got the error when
    doing a vo.executeQuery().
    When I removed the decode statement everything worked correctly. Does anyone know if
    the decode statement cannont be used in the select line of a query in a view object?
    Or maybe I was linking the query column (SCHOOLS_ID) up to the view attribute (SCHOOL_VALUE) incorrectly in the
    Attribute Mappings tab of the VO wizard?

    There should be no problem using a DECODE() statement, provided that you've aliases the column as you have done.
    At design time, if you click on the (Test) button, does your query test ok?
    Are you by chance applying a custom where clause at runtime?
    If so, are you saying:
    setWhereClause("yourtable.column_alias = ?";
    or are you doing:
    setWhereClause("column_alias = ?";
    for an expert-mode query, you'll need to use the latter syntax.

  • Reporting tax code lines

    Hello Every Body,
    For the tax code in reporting, can some one tell me witch line (in example below) get the priority in reporting ?
    Item = 1 and item = 2 ?
    OR
    Item = 2 and item = 3 ?
    We have to based on the field transaction(mws/vst)? if yes -> who get the priority ? mws or vst?
    Tax code:
    TR -->     Transfer to other EU country
    TX-->      acq of stock in DE
    Transaction:
    MWS-->
    Output Tax
    VST-->
    Input Tax
    WIA1-->
    Input Tax Dest. Ctry
    WIA2-->
    Output Tax Dep. Ctry
    WIA3-->
    Output Tax Dest.Ctry
    Thank u.
    Ouail.

    No Idea?

  • Mapping exceptions to source code lines

    From a JD-newbee: When an exception is thrown, it is always nice to get to know the exact line in the source code that caused the exception. I am currently unable to get such info, and suspect that this is due to JIT-compiling being active, but have been unable to figure out how to disable the JIT. Could anyone please let me know how to disable the JIT, or, if that's not the solution to my problem, tell me what I should do?

    Hi,
    try this report [https://wiki.sdn.sap.com/wiki/display/Snippets/SearchforStringsinABAPSourceCode].
    For counting the lines you specify a search string of
    The includes for classes can be specified by
    ZCL_XY*
    Best regards
    Thomas
    Edited by: Thomas Schulz on May 4, 2010 1:33 PM

Maybe you are looking for

  • New 27inch iMac, external Display "blinks" while in "Display Sleep"

    I just updated from a 24inch iMac to a 27inch iMac. I'm using the same setup for connecting the external display, which is a miniDisplay Port adapter(from Apple) to DVI, then DVI to the external monitor. All works fine until the "Sleep Display" kicks

  • Auto clear ip dhcp conflict *?

    Is there a command or config that will make a router automatically clear ip dhcp conflict * on a regular basis? I have a site that constantly has a problem with DHCP due to conflicts which is fixed simply by clearing the conflict table. If we could a

  • Writing Mp3 in garage band?

    I like to post some of my jams on my facebook etc, but they only accept Mp3 format. it seems that gargage band only writes in mp4... I know how to buy software to do this... but will the program write files in Mp3, without having to import 3rd party

  • Server/client application

    i'm just starting to learn about server/client applications and i'm a little confused about actually implementing them. my client will be an applet which can be accessed over the internet. i want the applet to be able to read/write to the server. now

  • Edit Appraisal through MSS

    Hi We are about to implemented MSS and Appraisal (MBO). I want to create an Appraisal via MSS but I'm not sure how to do that. When I select My staff -> Employee Review -> Edit Appraisals I get the message 'No suitable appraisal template is available