Can I use if statement in SQL???

Hello everyone.
I know that this is a silly question. The answer is no. Instead I should use decode function.
But what if I dont know all possible outcomes, can I still use decode function?
Also, I have created a view, in the where clause i want to use if statement. Is it possible to do?
Thanks in advance,
Sonya

here is the view that I created:
create or replace view import_shipment2
( order_no, cust_no,ORDER_SUFFIX,ship_addr1,ship_addr2, city,state,ZIP,country, terms_cd,shipvia_cd,
freight_cd, shipto_cdoehead,shipto_cdshipto,ship_name,ship_attn,order_status, org_unit_id, order_date,
estship_dt,confirm_status,gross_inv_value,phone,total_line_no,total_qty_order,total_qty_shipped,
total_qty_backordered,service,hold_cd,invno)
as select
to_char(c.order_no)||'_'||c.ORDER_SUFFIX, c.cust_no,c.ORDER_SUFFIX,d.ship_addr1,
     d.ship_addr2, b.city, b.state, b.zip_code,b.country, d.terms_cd,d.shipvia_cd,d.freight_cd, d.shipto_cd,b.shipto_cd,
     nvl(d.ship_name,b.shipto_attn), nvl2(d.ship_attn,b.shipto_attn,e.contact),d.order_status, d.org_unit_id,
     d.order_date, d.estship_dt, c.confirm_status, f.gross_inv_value ,nvl(d.shipto_recip_phone ,g.phone_no),
     sum(c.line_no),sum(c.qty_order),sum(c.qty_shipped),sum(c.qty_bo),d.shipvia_cd ,d.hold_cd,d.invno
from shipto_test b, oehead_test d,oedetl_test c, oesummary_test f ,CONTACT_MASTER_TEST e ,CONTACT_PHONE_TEST g
where c.order_no=d.order_no
and b.cust_no=d.cust_no
and b.shipto_cd=d.shipto_cd
and d.cust_no=f.cust_no
and d.order_no=f.order_no
and d.org_unit_id in ('110','120')
     and e.cust_no=d.cust_no
and e.shipto_cd= d.shipto_cd
and d.order_status in ('J','S')
and g.contact_id=e.contact_id
and g.phone_type='Business'
Group by
to_char(c.order_no)||'_'||c.ORDER_SUFFIX, c.cust_no,c.ORDER_SUFFIX,d.ship_addr1,
     d.ship_addr2, b.city, b.state, b.zip_code,b.country, d.terms_cd,d.shipvia_cd,d.freight_cd, d.shipto_cd,b.shipto_cd,
     nvl(d.ship_name,b.shipto_attn), nvl2(d.ship_attn,b.shipto_attn,e.contact),d.order_status, d.org_unit_id,
     d.order_date, d.estship_dt, c.confirm_status, f.gross_inv_value ,nvl(d.shipto_recip_phone ,g.phone_no),
     d.shipvia_cd ,d.hold_cd,d.invno;
I need to do the validation of the g.phone_type. Does phone number exist at all in table?
How do I all PL/SQL to this view??
Thanks once agin,
Sonya

Similar Messages

  • Can we use Loop Statement for Ranges

    Hi Friends,
    I have a range say R_Range. I need to loop at each line item and get the values in another range R_New_Range, i have to count the number of items in R_new_range. How is it possible.
    I know range is nothing but an internal table. So we can direcly use Move statements or so ...,
    But my question is .....
    My R_range has values as below
    'I' 'EQ' '001'
    'I' 'EQ' '002'
    'I' 'BT' '003' '007'
    'I' 'EQ' '008'
    I have to move all these values to R_New_range and my count of items should be '8'.
    How can i do that????????
    Expecting ur answers....
    Thanks in advance
    Cheers,
    R.Kripa.

    hey friends,
    Its nice to see the replies.... but i think i had confused u all with the question
    Now i'll explain u all in detail ....
    See i have 15000 projects ( eg., AAA111... ) and 100 GL accounts ( eg., 123443... ) .....
    I have to get the costs from COSS and COSP tables for all the projects - GL account combinations which leads to some 1500000 entries ..... So it is giving me a SQL Dump "DBIF_RSQL_INVALID_RSQL" .........
    Description of the Dump is
    Error in the module RSQL accessing the database interface
    An exception occurred. This exception is dealt with in more detail below
    . The exception, which is assigned to the class 'CX_SY_OPEN_SQL_DB', was
    neither                                                                
    caught nor passed along using a RAISING clause, in the procedure        
    "GET_COSP_COSS" "(FORM)"                                               
    Since the caller of the procedure could not have expected this exception
    to occur, the running program was terminated.                          
    The reason for the exception is:                                        
    The SQL statement generated from the SAP Open SQL Statement violates a  
    restriction imposed by the database system used in R/3.                                                                               
    Possible errors:                                                        
    o The maximum size of an SQL statement has been exceeded.              
    o The statement contains too many input variables.                     
    o The space needed for the input data exceeds the available memory.    
    o ...                                                                               
    You can usually find details in the system log (SM21) and in the        
    developer trace of the work process (ST11).                             
    If an error occurs the developer trace often informs you about the      
    current restrictions.                                                   
    So now i want to fine tune the program so that the execution works perfectly and get me the values for all the data 1500000 :-|
    Now :
    My Projects are stored in the form of a range R_Range
    I have to loop at this range and then process 100 records at a time and then again take other 100 records .... i'll count till 100 records by getting loopaing at the range and for each loop pass i'll increment the counter ....
    I am clear till this .....
    If record consist of 'EQ' option .... then ofcourse we can consider the total record to be 1 record and we can add 1 to counter ......
    But if the record consist of 'BT' option ...... then how can we loop that and get the number of -low numbers in that range and add to my counter ????
    Hope iam clear with my question
    If not do revert back ....
    Thanks in advance for the replies
    Cheers,
    R.Kripa.
    My Doubt is ....

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

  • How do we use if statement in labview?moreover can i use if statement inside for loop?

    how do we use if statement in labview?moreover can i use if statement inside for loop?

    The if statement in LabVIEW is the Case structure. You can find that on the Structures palette right next to the For Loop. If you're still on the same subject about terminating a for loop early, then what you do is enclose your functions inside the loop with a case statment and make one of the case's empty except for one or more constants that you might have to wire. Hopefully, the attached picture will explain what I mean. Also, as I mentioned in one of your other posts, I think this technique is not as good as using a while loop. The array in the attached example is the same size no matter what and you may have to handle stripping extra or invalid elements.
    Attachments:
    For_Loop_with_Case.jpg ‏21 KB

  • Can we use Perform statement in start routine ,Form and endform.

    Hi,
    Can we use Perform statement in start routine ? Then write the ABAP code between Form and Endform.
    Example : Can I use Perform ABC in start routine. Then define ABC at the end of start routine.
          Form ABC,
          ......<ABAP> code .....
          Endform.

    Hi,
    In BI 7.0 we have start routines defined using Class where you might be able to create your own performs, but in case of BW3.5 Start routines are defined using Form so there I don't think it will allow you to create one more form.
    But you can surely try both the approaches.
    Reards,
    Durgesh.

  • Can we use different Databases (Oracle & SQL Server) in one report?

    Post Author: venki5star
    CA Forum: .NET
    Hi there.
    Can we use different databases (Oracle & SQL Server) in a same report?
    If possible how?
    Another question,
    Can we change the Provider Name at runtime of the given report. If so the above question is useless...
    Thanks in Advance.

    I tried this using Oracle Provider for OLEDB (the one that supplied by Oracle Client) and Crystal Reports 9. you can drag the column into designer but the image does not appear in preview.
    I guess it's because CR does not recognized it as image, and there are no information that the blob data is an image at all.

  • Can I use case statements in triggers?

    I created this trigger, it works BUT I don't like those parentheses at the begining, I would like
    to change those parentheses for case statements, well that is my question, can you use case statements in triggers, how you would translate the following in case statement?
    FOR EACH ROW
    WHEN ( (new.sgbstdn_levl_code = 'UG')
    and
    ( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
    OR
    ( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
    (NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
    (OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
    ==================================================================================================
    CREATE OR REPLACE TRIGGER CC_STUD_WITHDRAWAL
    AFTER UPDATE OR INSERT ON SATURN . SGBSTDN
    FOR EACH ROW
    WHEN ( (new.sgbstdn_levl_code = 'UG')
    and
    ( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
    OR
    ( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
    (NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
    (OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
    DECLARE
    v_params gokparm.t_parameterlist;
    event_code gtveqnm.gtveqnm_code%TYPE;
    firstname spriden.spriden_first_name%TYPE;
    lastname spriden.spriden_last_name%TYPE;
    middlename spriden.spriden_mi%TYPE;
    id spriden.spriden_id%TYPE;
    CURSOR get_stud_name IS
    SELECT
    spriden_id ,
    spriden_last_name ,
    spriden_first_name ,
    spriden_mi
    FROM
    saturn.spriden
    WHERE spriden_pidm = :NEW.SGBSTDN_PIDM
    AND spriden_change_ind IS NULL;
    BEGIN
    IF goksyst . f_isSystemLinkEnabled ( 'WORKFLOW' ) THEN
    event_code := SUBSTR ( gokevnt.F_CheckEvent ( 'WORKFLOW' ,'CC_STUDENT_WITHDRAW' ),1,20);
    OPEN get_stud_name ;
    FETCH get_stud_name INTO id , lastname , firstname , middlename ;
    CLOSE get_stud_name ;
    ----pass parameters to the event
    v_params ( 1 ).param_value := 'CC_STUDENT_WITHDRAW' ;
    v_params ( 2 ).param_value := '' ;
    v_params ( 3 ).param_value := 'Student Withdrawal:' || lastname || ',' || firstname || ' ' ||
    middlename ;
    v_params ( 4 ).param_value := :NEW.sgbstdn_pidm ;
    v_params ( 5 ).param_value := id ;
    v_params ( 6 ).param_value := lastname ;
    v_params ( 7 ).param_value := firstname ;
    v_params ( 8 ).param_value := middlename ;
    v_params ( 9 ).param_value := :NEW.sgbstdn_term_code_eff ;
    v_params ( 10 ).param_value := :NEW.SGBSTDN_STST_CODE ;
    v_params ( 11 ).param_value := :NEW.SGBSTDN_STYP_CODE ;
    gokparm.Send_Param_List ( event_code , v_Params );
    END IF;
    END;
    /

    You could delete a fair number of extraneous parentheses.
    CREATE OR REPLACE TRIGGER cc_stud_withdrawal
      AFTER UPDATE OR INSERT
      ON saturn.sgbstdn
      FOR EACH ROW
      WHEN     NEW.sgbstdn_levl_code = 'UG'
           AND (   NEW.sgbstdn_stst_code NOT IN ('GR', 'SA', 'AS', 'IS')
                OR (    NEW.sgbstdn_stst_code = 'IS'
                    AND NEW.sgbstdn_styp_code IN ('N', 'T')
                    AND OLD.sgbstdn_stst_code = 'AS'))

  • Can i use select statements in LDB

    Hai All,
       Can i use select statements and internal table in a LDB program.
    my requirement is that if i enter company code , fiscal year and reporting periods.
    generally fiscal year will be jan to dec.but in my requirement the fiscal year is apr of previous year to march of currentyear.
    so as i require the last years data can iuse select statement in that ldb program or is there any solution for this.
    Thanks in Advance
    kiran

    Hi Kiran,
    To retrive records from ldb you have to use the
    GET <node> statement. This will invoke the selection screen of the node. An alternate solution is to use the function module LDB_PROCESS.
    Please see the following link for help and example
    http://help.sap.com/saphelp_nw04/helpdata/en/64/237f8cd43711d1950b0000e8353423/content.htm
    Thanks
    Vinod

  • Can we use IF statement in PDF templates

    Hi,
    I developed a PDF template. I need to underline ang bold the records based on a specific condition. Can we use IF conditon in PDF templates. Please suggest.
    Thanks...

    Billy  Verreynne  wrote:
    The case syntax is a bit funny though as there's not a single condition evaluation (like a DECODE or case structs from some other languages).
    This is what I would expect a typical case struct to look like - evaluating a single condition:
    case <condition>
    when <value-1> then return <result-1>
    when <value-n> then return <result-n>
    else
    return <return-z>
    end
    ?:| You mean like this...?
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, ename, deptno
      2        ,case deptno
      3           when 10 then 'This is Department 10'
      4           when 20 then 'And department 20'
      5           when 30 then 'And of course department 30'
      6         else
      7           'Blimey it is something else!'
      8         end as dept_desc
      9* from emp
    SQL> /
         EMPNO ENAME          DEPTNO DEPT_DESC
          7369 SMITH              20 And department 20
          7499 ALLEN              30 And of course department 30
          7521 WARD               30 And of course department 30
          7566 JONES              20 And department 20
          7654 MARTIN             30 And of course department 30
          7698 BLAKE              30 And of course department 30
          7782 CLARK              10 This is Department 10
          7788 SCOTT              20 And department 20
          7839 KING               10 This is Department 10
          7844 TURNER             30 And of course department 30
          7876 ADAMS              20 And department 20
          7900 JAMES              30 And of course department 30
          7902 FORD               20 And department 20
          7934 MILLER             10 This is Department 10
    14 rows selected.

  • How can I use the Rownum/Customized SQL query in a Mapping?

    Hi,
    * I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
    * How can I use an Dual table in OWB mapping?
    * Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
    Thanks in Advance
    Kishan

    Hi Niels,
    As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
    Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
    Hope this helps...
    regards,
    Stewart

  • Can I use if statement in side FIX

    Can I use like this..would this improve better performance.<BR>Say dimension, Temp has member1,member2 and member3<BR><BR>FIX ("Member1","Member2")<BR>IF(@ISMBR(("net"))"403"*0.20;<BR>ENDIF;<BR>ENDFIX<BR><BR>instead of <BR><BR>IF (@ISMBR("Member1","Member2"))<BR>IF(@ISMBR((""net"))"403"*0.20;<BR>ENDIF;<BR>ENDIF;

    <p>Yes you can.</p><p> </p><p>Try using this</p><p> </p><p>  <span style=" color: #ff9933;">  FIX("Member1","Member2")   </span></p><p>         <spanstyle=" color:#ff9933;"> "net"(    </span></p><p>    <span style=" color:#ff9933;">            IF(@ISMBR(("net"))</span></p><p><span style=" color:#ff9933;">                    "403"*0.20;</span></p><p><span style=" color:#ff9933;">                ENDIF;</span></p><p><span style=" color:#ff9933;">            )</span></p><p><span style=" color:#ff9933;">    ENDFIX</span></p>

  • Can we use if/else in sql statement?

    Hi,
    Is it possible to write a sql statement like the one below (not plsql)?
    if (select 'True' from dual) = 'True' -- 1
    then
    select 'True' from dual;  -- 2
    else
      select 'False' from dual; -- 3
    endBasically, I want to execute either sql 2 or 3 based on the result of sql 1. I'm not sure if this is possible using only sql and not having to write a stored proc.
    What are the different ways I can implement this?
    Thanks for the help.

    Billy  Verreynne  wrote:
    The case syntax is a bit funny though as there's not a single condition evaluation (like a DECODE or case structs from some other languages).
    This is what I would expect a typical case struct to look like - evaluating a single condition:
    case <condition>
    when <value-1> then return <result-1>
    when <value-n> then return <result-n>
    else
    return <return-z>
    end
    ?:| You mean like this...?
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, ename, deptno
      2        ,case deptno
      3           when 10 then 'This is Department 10'
      4           when 20 then 'And department 20'
      5           when 30 then 'And of course department 30'
      6         else
      7           'Blimey it is something else!'
      8         end as dept_desc
      9* from emp
    SQL> /
         EMPNO ENAME          DEPTNO DEPT_DESC
          7369 SMITH              20 And department 20
          7499 ALLEN              30 And of course department 30
          7521 WARD               30 And of course department 30
          7566 JONES              20 And department 20
          7654 MARTIN             30 And of course department 30
          7698 BLAKE              30 And of course department 30
          7782 CLARK              10 This is Department 10
          7788 SCOTT              20 And department 20
          7839 KING               10 This is Department 10
          7844 TURNER             30 And of course department 30
          7876 ADAMS              20 And department 20
          7900 JAMES              30 And of course department 30
          7902 FORD               20 And department 20
          7934 MILLER             10 This is Department 10
    14 rows selected.

  • Can we use repository variables in SQL statement of column prompt?

    Hi Dudes,
    Below is the query
    SELECT "- End Date"."End Fiscal Year" FROM "Consumer Sector" WHERE ("- End Date"."End Fiscal Year" = valueof (current_year)) or ("- End Date"."End Fiscal Year" = valueof (current_year) -1)
    when use this sql in criteria prompt getting error.
    Please suggest .
    thanks.sri

    Make sure your syntax is correct it should be like VALUEOF("CURRENT_YEAR")-1
    If you still have issues then VALUEOF("CURRENT_YEAR")-1 cast it to int before you subtract.
    If helps pls mark as correct else let share error message

  • Can we use SELECT statement within IF..?

    DECLARE
    A NUMBER;
    BEGIN
    IF (SELECT '2' FROM DUAL) = 2 THEN
    A := 2;
    END IF;
    DBMS_OUTPUT.PUT_LINE(A);
    END;

    Did you tried to execute it. The error itself is an explanation
    ORA-06550: line 5, column 5:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null <an identifier>
    <a double-quoted delimited-identifier> <a bind variable>
    continue avg count current exists max min prior sql stddev
    sum variance execute forall merge time timestamp interval
    date <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternat
    ORA-06550: line 5, column 27:
    PLS-00103: Encountered the symbol "=" when expecting one of the following:
    ) , and orNo, we can not
    You can have expressions in IF statement but not a query. Instead, you can capture in a variable and then compare in IF
    declare
    a number;
    begin
    select 2 into a from dual;
    if a = 2 then
    dbms_output.put_line(1);
    end if;
    end;
    /

  • Why i can not use dbco to connect sql server 2008?

    Dear Experts,
        i use this mehtod to link sql server 2005 :MSSQL_SERVER=tcp:mysqlserver IP  MSSQL_DBNAME=SubConPayment,
    it is ok,when i use this method to link sql server 2008 with dbco,it is not ok,can you tell me why i can not link to sql server2008 in sap with dbco?
    looking forward to your reply.
    Best regards,
    Merry

    Hi Merry,
    Seems that you have to add the "provider" attribute to the connectionstring. Please have a look at the following link: [http://www.connectionstrings.com/sql-server-2008#p2]
    Regards,
    Ozcan.

Maybe you are looking for

  • ThinkPad T530 - 3 External monitors

    Hi, I don't manage to get the third external screen working on my pc. I manage to have two external screen and my laptop screen, however, I want to have all three external screen to work simulatenusly, and the laptop closed in the docking station. Do

  • Macbook Air and Keynote performance

    I'm very happy with my Macbook Air so far (except for the trackpad button that seems to be unresponsive at times). BUT. I chose the Air to use it for Keynote presentations. I'm a little bit upset to see that some Keynote effects that I like such as c

  • Windows Server 2012 CA will not allow Windows XP to autoenroll

    I have a Windows Server 2012 Domain Controller with an Enterprise root CA installed.  I have created a client authentication certificate template (2003 compatible).  Domain Computers have Read, Enroll and Autoenroll permissions.  I modified the Domai

  • -5o error in Imovie 11

    When I try to finalize a project in Imovie 11, I got the message -50 error (the project coul;dn't be finalized). It is a 1080i recording from a Sony HDR HCE1, total length is 55 minutes.

  • Printer won't stop printing.

    Asked for six copies of a one page document and won't stop even after pressing cancel printing. HP Officejet 6500 Windows 7 This question was solved. View Solution.