Error in writing the CASE statement

i am writing these lines for my procedure getting error in writing CASE Statement when i remove case give result please any suggestion
SELECT OTServicesMapping.ServiceId,Service_mst.Service_Name,
OTServicesMapping.DependentOn,
CASE OTROLEID -----error in this line
WHEN (SELECT NVL(ChiefSurgeonServiceId,0) FROM ConfigOTService) = OTServicesMapping.ServiceId THEN 1
else 0
end,
OTServicesMapping.OTPercent
FROM Service_mst INNER JOIN
OTServicesMapping ON Service_mst.Service_ID =OTServicesMapping.ServiceId LEFT OUTER JOIN
Service_mst Service_mst_1 ON OTServicesMapping.DependentOn = Service_mst_1.Service_ID
ERROR
SQL Error: ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:   
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Hi,
What part does otroleid play in this problem? Why can't you say:
CASE
     WHEN ( SELECT  NVL (ChiefSurgeonServiceId, 0)
              FROM    ConfigOTService
          ) = OTServicesMapping.ServiceId  THEN 1
                                  ELSE 0
END, ?
Will there ever be more than 1 row in the ConfigOTService table? If so, you'll have a different error.
Whenevder you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data.
QAlways say what version of Oracle you're usiing.

Similar Messages

  • How do I use the CASE statement  in the where clause?

    Hello Everyone,
    I have 2 queries that do what I need to do but I am trying to learn how to use the CASE statement.
    I have tried to combine these 2 into one query using a case statement but don't get the results I need.
    Could use some help on how to use the case syntax to get the results needed.
    thanks a lot
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 60)
    GROUP BY 1,2
    order by product_type
    select segment_name,
    product_type,
    count (distinct account_id)
    FROM NL_ACCT
    where
    ind = 'N'
    and
    EM_ind = 'N'
    and product_type not in ('TAX','PAY')
    and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 30)
    group by 1,2
    order by product_type

    Something like:
    SELECT segment_name, product_type,
           SUM(CASE WHEN account_id IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60 THEN 1
                    ELSE 0 END) tax_pay,
           SUM(CASE WHEN account_id NOT IN ('TAX','PAY') and
                         acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 30 THEN 1
                    ELSE 0 END) not_tax_pay
    FROM NL_ACCT
    WHERE ind = 'N' and
          em_ind = 'N' and
          acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
                               TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60
    GROUP BY segment_name, product_type
    ORDER BY product_typeNote: You cannor GROUP BY 1,2, you need to explicitly name the columns to group by.
    HTH
    John

  • Error when writing the trace in ST01

    Hi Gurus,
    Good day!
    Please advise on how can I resolve this issue in ST01. I'm getting an error "Error when writing the trace No such file or directory".
    Appreciate your help.
    Cheers,
    Virgilio

    Hi,
    Check this link
    http://help.sap.com/saphelp_nw04/helpdata/EN/ae/ed0ad513d0074e944879f05ef318d5/content.htm
    Regards,
    Renu

  • Decode Statement Inside the Case statement

    Can we use Decode Statement inside a CASE Statement as show below --
    It is giving an error -- Is the a better way to write with out any error
    create or replace
    function test (a varchar2) RETURN VARCHAR2
    is
    m varchar2(20);
    begin
    m :=
    CASE
    WHEN a IN (
    '1009' -- (soon obsolete)
    ,'1010'
    ,'1019'
    ,'1051'
    ,'XGP'
    ,'XSC')
    THEN (SELECT DECODE(v_lef_cd,'NAM','71','GLB','99','01') into m FROM DUAL)
    -- ) THEN '01' -- UNITED STATES OF AMERICA
    WHEN a IN (
    '1069' -- South Africa
    ,'SAO' -- South Africa
    ,'SA' -- South Africa
    ) THEN '26' -- South Africa
    ELSE NULL
    END;
    return m;
    end;

    Hi,
    You can only use DECODE in SQL statements.
    Your SELECT DECODE (...) INTO statement would work anywhere a PL/SQL statement is allowed; but PL/SQL statements are not allowed within CASE expressions.
    Remember, the expression that comes after THEN in a CASE expression must be a single value.
    I would write a function like this using IF ... ELSIF statements. It's a little more typing than CASE, but a lot easier to code, test and maintain.
    If you want to use CASE, here's one way:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  NOT IN ('1009', '1019', '1051', 'XGP', 'XSC')
              OR    a  IS NULL
                   THEN  NULL
              WHEN  v_lef_cd = 'NAM'
                   THEN  '71'
              WHEN  v_lef_cd = 'GLB'
                   THEN  '99'
                   ELSE  '01'     -- USA
              END;This assumes that you have a variable v_lef_cd defined.
    If you want, you can nest CASE expressions, like this:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  IN ('1009', '1019', '1051', 'XGP', 'XSC')
                   THEN  CASE  v_lef_cd
                          WHEN  'NAM'
                             THEN  '71'
                          WHEN  'GLB'
                             THEN  '99'
                             ELSE  '01'     -- USA
                         END
              END;Always format your code, so you can see where the CASE expressions and each of the WHEN clauses begin and end.
    When posting formatted text on this site, type these 6 characters:
    (all small letters, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Error when generating the SQL statement while running the Query

    Hello SDN Mates,
    Am using three cubes in one infoset and build a query on that. Intially it was running fine, but now am getting error generating the SQL statement. Can you please throw some light on this. Your idea would be highly appreciated.
    Thanks and Regards
    Arun S

    Hi Arun
    is there any change in the objects (Check also the consistency of infoobject ) included in infoset, just make sure those are active, open the query in designer and check if no error/warning message are present
    Thanks
    Tripple k

  • Error while writing the data into the file . can u please help in this.

    The following error i am getting while writing the data into the file.
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="code">
    <code>null</code>
    </part>
    <part name="summary">
    <summary>file:/C:/oracle/OraBPELPM_1/integration/orabpel/domains/default/tmp/
    .bpel_MainDispatchProcess_1.0.jar/IntermediateOutputFile.wsdl
    [ Write_ptt::Write(Root-Element) ] - WSIF JCA Execute of operation
    'Write' failed due to: Error in opening
    file for writing. Cannot open file:
    C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing. ;
    nested exception is: ORABPEL-11058 Error in opening file for writing.
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation
    \WORKDIRS\SampleImportProcess1\input for writing. Please ensure 1.
    Specified output Dir has write permission 2.
    Output filename has not exceeded the max chararters allowed by the
    OS and 3. Local File System has enough space
    .</summary>
    </part>
    <part name="detail">
    <detail>null</detail>
    </part>
    </bindingFault>

    Hi there,
    Have you verified the suggestions in the error message?
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing.
    Please ensure
    1. Specified output Dir has write permission
    2. Output filename has not exceeded the max chararters allowed by the OS and
    3. Local File System has enough space
    I am also curious why you are writing to a directory with the name "..\SampleImportProcess1\input" ?

  • Invalid cursor state error while executing the prepared statement

    hai friends,
    following code showing the invalid cursor state error while executing the second prepared statement.
    pls anyone help me
    String query = "select * from order_particulars where order_no=" + orderno + " order by sno";             psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);             rs1 = psmt1.executeQuery();             rs1.last();             intRowCount = rs1.getRow();             particularsdata = new Object[intRowCount][6];             rs1.beforeFirst();             if (intRowCount >= 1) {                 for (int i = 0; rs1.next(); i++) {                     particularsdata[0] = i + 1;
    particularsdata[i][1] = rs1.getString(3);
    particularsdata[i][2] = Double.parseDouble(rs1.getString(4));
    rs1.close();
    psmt1.close();
    query = "SELECT sum(delqty) FROM billdetails,billparticulars WHERE order_no= " + orderno + " and " +
    "billdetails.bill_no = billparticulars.bill_no GROUP BY particulars ORDER BY sno";
    psmt1 = conEntry.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs1 = psmt1.executeQuery(); //error showing while executing this line

    Also .. Why using arrays instead of collections? Shifting the cursor all the way forth and back to get the count is fairly terrible.
    With regard to the problem: either there's a nasty bug in the JDBC driver used, or you actually aren't running the compiled class version of the posted code.

  • Oracle Error while execute the Select statement

    Hi all,
    I have two database, from one databse to another datadase, i am not able get value. while i am generating the select statement in one database, it throws an
    error ORA-00942: table or view does not exist.
    For this, what i have to do.can anyone post more detail on this.
    Any idea?

    Please do not create duplicate threads.
    ORA-00942: table or view does not exist

  • Error in writing execute immendiate statement

    i am writing this SQL procedure i have made use of dynamic SQL in this .... on compilation this is giving
    me error
    procedure
    create or replace
    PROCEDURE USP_GETMSTORDERFORBATCHSMPGENE
    v_pUserid IN NUMBER ,
    v_pFromDate IN DATE ,
    v_pToDate IN DATE ,
    v_pVisitTypeID IN NUMBER ,
    v_pWardID IN NUMBER ,
    v_pSubDeptID IN NUMBER ,
    v_plocid IN char
    AS
    v_Sql NVARCHAR2(4000);
    BEGIN
    v_Sql := '';
    v_Sql := 'SELECT DISTINCT
    OrderMst.OrdNo,OrderMst.OrdDateTime,OrderMst.OrdId,LABSampleType.ID AS SampleTypeID,LABSampleType.SampleType,
    NVL(LABSampleType.SampleCode, '''') AS SampleCode,SubDepartment_Mst.SubDepartment_Name,Visit.VisitTypeID,Ward_Mst.Ward_ID,
    Patient.First_Name || '''' '''' || Patient.Middle_Name || '''' '''' || Patient.Last_Name AS Patient,Patient.Registration_No,Visit.VisitNo
    FROM OrderDtl INNER JOIN
    OrderMst ONOrderDtl.OrdID =OrderMst.OrdId INNER JOIN
    Service_Mst ONOrderDtl.ServiceId =Service_Mst.Service_ID INNER JOIN
    LABTest ONService_Mst.Service_ID =LABTest.ServiceID INNER JOIN
    LABSampleType ONLABTest.SampleType =LABSampleType.ID INNER JOIN
    Visit ONOrderMst.OrdVisitID =Visit.Visit_ID INNER JOIN
    Patient ONVisit.PatientID =Patient.PatientId INNER JOIN
    SubDepartment_Mst ONService_Mst.SubDepartmentId =SubDepartment_Mst.SubDepartment_ID LEFT OUTER JOIN
    Ward_Mst ONVisit.WardID =Ward_Mst.Ward_ID
    WHERE (OrderDtl.OrdDtlID NOT IN (SELECT OrderDtlID FROM LABSampleDtl)) And
    TO_CHAR(OrderMst.OrdDateTime,''DD-MON-YYYY'') Between
    ''' || TO_CHAR( v_pFromDate, 'DD-MON-YYYY') || ''' And
    ''' ||TO_CHAR( v_pToDate, 'DD-MON-YYYY') || '''
    and (Cancelled = 0 or Cancelled is null)
    and SubDepartment in (select subdetartmentid from userdepartment where userid = ' || CAST(v_pUserid AS VARCHAR2) || ') and OrderMst.locid='|| v_plocid;
    IF v_pSubDeptID != 0 THEN
    v_Sql := v_Sql || ' AND LABTest.SubDepartment = ' || CAST(v_pSubDeptID AS VARCHAR2) || '';
    END IF;
    IF v_pVisitTypeID != 0 THEN
    v_Sql := v_Sql || ' AND Visit.VisitTypeID = ' || CAST(v_pVisitTypeID AS VARCHAR2) || '';
    END IF;
    IF v_pWardID != 0 THEN
    v_Sql := v_Sql || ' AND Visit.WardID = ' || CAST(v_pWardID AS VARCHAR2) || '';
    END IF;
    --DBMS_OUTPUT.PUT_LINE((v_Sql));
    EXECUTE IMMEDIATE v_Sql;----- error coming in this line
    END;
    ERROR
    Error(55,22): PLS-00382: expression is of wrong type
    Edited by: user21354 on Mar 23, 2011 11:53 PM

    Looks like this is your problem:
    INNER JOIN
    Service_Mst ONOrderDtl.ServiceId =Service_Mst.Service_ID INNER JOIN
    LABTest ONService_Mst.Service_ID =LABTest.ServiceID INNER JOIN
    LABSampleType ONLABTest.SampleType =LABSampleType.ID INNER JOIN
    Visit ONOrderMst.OrdVisitID =Visit.Visit_ID INNER JOIN
    Patient ONVisit.PatientID =Patient.PatientId INNER JOIN
    SubDepartment_Mst ONService_Mst.SubDepartmentId =SubDepartment_Mst.SubDepartment_ID LEFT OUTER JOIN
    Ward_Mst ONVisit.WardID =Ward_Mst.Ward_IDYou're missing a space after every 'ON'
    Plus in addition to what others have said I really don't believe this is what you want:
    And
    TO_CHAR(OrderMst.OrdDateTime,''DD-MON-YYYY'') Between
    ''' || TO_CHAR( v_pFromDate, 'DD-MON-YYYY') || ''' And
    ''' ||TO_CHAR( v_pToDate, 'DD-MON-YYYY') || '''Also if you're executing a dynamic select statement you need to provide a place for it to put the results.
    Also I don't see any reason that this needs to be dynamic. You could just as easily have this:
    create or replace
    PROCEDURE USP_GETMSTORDERFORBATCHSMPGENE
       v_pUserid IN NUMBER ,
       v_pFromDate IN DATE ,
       v_pToDate IN DATE ,
       v_pVisitTypeID IN NUMBER ,
       v_pWardID IN NUMBER ,
       v_pSubDeptID IN NUMBER ,
       v_plocid IN char
    AS
    BEGIN
      SELECT DISTINCT OrderMst.OrdNo
                     ,OrderMst.OrdDateTime
                     ,OrderMst.OrdId
                     ,LABSampleType.ID AS SampleTypeID
                     ,LABSampleType.SampleType
                     ,LABSampleType.SampleCode AS SampleCode
                     ,SubDepartment_Mst.SubDepartment_Name
                     ,Visit.VisitTypeID
                     ,Ward_Mst.Ward_ID
                     ,Patient.First_Name || ' ' || Patient.Middle_Name || ' ' || Patient.Last_Name AS Patient
                     ,Patient.Registration_No
                     ,Visit.VisitNo
      -- INTO something goes here
        FROM OrderDtl
          INNER JOIN OrderMst ON OrderDtl.OrdID =OrderMst.OrdId
          INNER JOIN Service_Mst ON OrderDtl.ServiceId =Service_Mst.Service_ID
          INNER JOIN LABTest ON Service_Mst.Service_ID =LABTest.ServiceID
          INNER JOIN LABSampleType ON LABTest.SampleType =LABSampleType.ID
          INNER JOIN Visit ON OrderMst.OrdVisitID =Visit.Visit_ID
          INNER JOIN Patient ON Visit.PatientID =Patient.PatientId
          INNER JOIN SubDepartment_Mst ON Service_Mst.SubDepartmentId =SubDepartment_Mst.SubDepartment_ID
          LEFT OUTER JOIN Ward_Mst ON Visit.WardID =Ward_Mst.Ward_ID
       WHERE (OrderDtl.OrdDtlID NOT IN (SELECT OrderDtlID FROM LABSampleDtl))
         And OrderMst.OrdDateTime Between v_pFromDate And v_pToDate
         and (Cancelled = 0 or Cancelled is null)
         and SubDepartment in
            (select subdetartmentid from userdepartment where userid = CAST(v_pUserid AS VARCHAR2))
         and OrderMst.locid= v_plocid
         AND nvl(LABTest.SubDepartment,'0') = CASE when v_pSubDeptID != 0
                                                   then CAST(v_pSubDeptID AS VARCHAR2)
                                                   else nvl(LABTest.SubDepartment,'0')
                                              END
         AND nvl(Visit.VisitTypeID,'0') = CASE when v_pVisitTypeID != 0
                                               then CAST(v_pVisitTypeID AS VARCHAR2)
                                               else nvl(Visit.VisitTypeID,'0')
                                          END
         AND nvl(Visit.WardID,'0') = CASE WHEN v_pWardID != 0
                                          THEN CAST(v_pWardID AS VARCHAR2)
                                          ELSE nvl(Visit.WardID,'0')
    END;

  • Error while executing the Alter statement

    ORA-00604: error occurred at recursive SQL level 1
    ORA-01654: unable to extend index SYS.I_COL2 by 64 in tablespace SYSTEM
    Im facing the above issue , while executing the Alter . Any solution on this . How to Overcome this ...

    It would have been nice if you'd bothered to actually post the statement causing this error.
    However, I think it is simply that you have run out of room in the system tablespace.
    In which case, ask your DBA to increase the size of that tablespace.

  • Error showing in the import statement

    Hi there........
    I am working on mobile project of expense managemnt.
    in that code i started with following statements.
    import java.sql.*;
    i am using the CDC 1.0 toolkit.
    it shows the error that statement does not exist & errors for class.
    Is it necessary to use additional API for implementing embedded SQL in mobile.
    SO,
    please tell me immediately

    hi thanks for your reply
    i have loaded tomcat4.1 exe -- for windows i am starting the tomcat server by clicking from the start menu..
    i dint set any env variable .. tell me how to set...
    regards
    ijay

  • Errors when using the Call statement for MS SQL Server

    I've tried executing a Stored Procedure using the Call method of Portal 2 Go. But it gets an internal error b/c of it. Any Ideas why and how to resolve?

    Hello,
    Which version of SAP BOBJ XI3.1 you are using?
    What I am aware is BEGIN_SQL was very well working for SQLServer2005 in case of ODBC connection.
    Can you try one thing for SQLServer2008 have a Native driver installed on your client machine and use ODBC connection rather than OLEDB connection.
    If that works fine, its good
    Otherwise you can raise a message for resolving this problem with the support team.
    Thanks,
    Vivek

  • Can we use alias name in the case statement?

    select sal,
    case sal
    when 500 then 'low'
    when 5000 then 'high'
    else 'medium'
    end case
    from emp;
    OUTPUT
    sal    case
    4587 medium
    5000 high
    .....so  can i have range in the place of  case  at output?

    select nvl(sal,0) sal, case when nvl(sal,0)<=500 then 'low' when nvl(sal,0)>=5000 then 'high' else 'medium' end range from emp;
    Output
    SAL RANGE
    450 low
    5000 high
    300 low
    4000 medium
    3700 medium
    4750 medium
    2000 medium

  • Length error occurred during the IMPORT statement.

    i have problem in Zprogram.its working fine in 4.6b ,but its problem in ECC5.0.its giving dump and saying
    Error analysis                                                                     
       An exception occurred. This exception will be dealt with in more detail        
    below. The exception, assigned to the class 'CX_SY_IMPORT_MISMATCH_ERROR', was 
    not caught, which  led to a runtime error. The reason for this exception is:         
    The system found when importing that the target object was longer or   
    shorter than the object to be imported.

    Hi Madhu,
    Suggested to post this in logistics forum for better answer.
    Software Logistics
    Regards,
    Debasis.

  • Error message in the loop statement

    Hi Experts:
                    In my ABAP program,
                    In the loop of internal table,when match some condition,the system give error message, or go on.
                    Now,if the internal table has ten records,  three records match some condition,the others need
                           process going on.
                    But in my program,if finds error record,giving error message,can't process other records.
                    I want it can not only show error message,but also process other records.
                    Pls give me some advice,tks!

    Hi,
    Message type E is error type and it will terminate your program.
    So either we can declare the message type E as information message or status or we can add a varaible flag which can be set on error.
    So that it would not terminate the program.
    Example :
    Loop at inttable1.
    if condition for error
    flag = 'X'.
    continue.
    endif.
    endloop.
    Outside the loop.
    if flag = 'X'.
    message in other internal table with details.
    endif
    Hope this helps.
    Thanks,

Maybe you are looking for

  • Inbound delivery replication ECC - EWM

    Hello, I am currently trying to link a SAP ECC 6.00 system to a SAP SCM5.00 in order to use eWM. The RFC destinations are correctly customized and the master data is correctly replicated between the central and decentral system (via the CIF) => <i>I'

  • Software Updates, multiple SAME search criteria ?

    Hi Does anyone know if you can have multiple SAME Software Update Search search criteria?  For example if I add the same search criteria twice I will get the OR and not AND criteria that I want. How would I go about doing that?

  • Need help on coverting sql statement to NamedQueries

    hi, all, I have a problem on converting the following SQL statement returning last 10 records from an Oracle database. The SQL statement is as followings: select * from (select * from TABLE1 where ATT1 = 1 order by ATT2 desc) where rownum<11 However,

  • Web Services and the Developer Mindset

    "Web Services has all the makings of a home run. As a powerful integration platform, it moves the procedural-heavy complexities of building distributed apps into the realm of simple declarative transactions, while supporting location transparency. It

  • Full screen picture for contacts

    I have recently upgrade to the iphone 5. I use MS Exchange to sync contacts and email. I want to have full screen picture for caller ID but it only gives me a thumbnail. Any suggestions to get full screen picture for caller ID?