A few tricky SQL statements

I'm trying to do two fairly tricky SQL statements for a class, and been trying for a while and have gotten stuck.
The first one is, "Find Courses where more than half the students got an A"
I've basically been trying to use not exist statements to set it up and then compared the count(sid)/2 > count(sid) query of all A's and am just not getting decent results from it.
The REALLY tricky one is "Find the pairs of students who took exactly the same set of courses"
I can get a cross product from all students with something like this
SELECT s1.sname, s2.sname
FROM lab6_student s1, lab6_student s2
WHERE s1.sname > s2.sname
but after that I can't seem to get it to work properly at all.
Thanks for any pointers/advice!

1.
SQL> WITH T
  2       AS (SELECT 'mathematics' course_name, 'john' student_name, 'A' grade FROM DUAL
  3           UNION ALL
  4           SELECT 'mathematics' course_name, 'john1' student_name, 'A' grade FROM DUAL
  5           UNION ALL
  6           SELECT 'mathematics' course_name, 'john2' student_name, 'A' grade FROM DUAL
  7           UNION ALL
  8           SELECT 'mathematics' course_name, 'john3' student_name, 'B' grade FROM DUAL
  9           UNION ALL
10           SELECT 'physics' course_name, 'john' student_name, 'A' grade FROM DUAL
11           UNION ALL
12           SELECT 'physics' course_name, 'john1' student_name, 'B' grade FROM DUAL
13           UNION ALL
14           SELECT 'physics' course_name, 'john2' student_name, 'B' grade FROM DUAL
15           UNION ALL
16           SELECT 'physics' course_name, 'john3' student_name, 'B' grade FROM DUAL)
17  SELECT   *
18    FROM   T;
COURSE_NAME STUDE G
mathematics john  A
mathematics john1 A
mathematics john2 A
mathematics john3 B
physics     john  A
physics     john1 B
physics     john2 B
physics     john3 B
8 rows selected.
SQL> WITH T
  2       AS (SELECT 'mathematics' course_name, 'john' student_name, 'A' grade FROM DUAL
  3           UNION ALL
  4           SELECT 'mathematics' course_name, 'john1' student_name, 'A' grade FROM DUAL
  5           UNION ALL
  6           SELECT 'mathematics' course_name, 'john2' student_name, 'A' grade FROM DUAL
  7           UNION ALL
  8           SELECT 'mathematics' course_name, 'john3' student_name, 'B' grade FROM DUAL
  9           UNION ALL
10           SELECT 'physics' course_name, 'john' student_name, 'A' grade FROM DUAL
11           UNION ALL
12           SELECT 'physics' course_name, 'john1' student_name, 'B' grade FROM DUAL
13           UNION ALL
14           SELECT 'physics' course_name, 'john2' student_name, 'B' grade FROM DUAL
15           UNION ALL
16           SELECT 'physics' course_name, 'john3' student_name, 'B' grade FROM DUAL)
17  SELECT   *
18    FROM   (SELECT     course_name, COUNT (*) total_cnt, SUM (CASE WHEN grade = 'A' THEN 1 ELSE 0 END) grade_cnt
19                FROM   T
20            GROUP BY   course_name)
21   WHERE   grade_cnt > total_cnt / 2;
COURSE_NAME  TOTAL_CNT  GRADE_CNT
mathematics          4          3
SQL>
2.
SQL> WITH T
  2       AS (SELECT '1' course_id, 'john' student_name FROM DUAL
  3           UNION ALL
  4           SELECT '2' course_id, 'john' student_name FROM DUAL
  5           UNION ALL
  6           SELECT '1' course_id, 'peter' student_name FROM DUAL
  7           UNION ALL
  8           SELECT '2' course_id, 'peter' student_name FROM DUAL
  9           UNION ALL
10           SELECT '3' course_id, 'king' student_name FROM DUAL
11           UNION ALL
12           SELECT '4' course_id, 'king' student_name FROM DUAL)
13  SELECT   *
14    FROM t;
C STUDE
1 john
2 john
1 peter
2 peter
3 king
4 king
6 rows selected.
SQL> WITH T
  2       AS (SELECT '1' course_id, 'john' student_name FROM DUAL
  3           UNION ALL
  4           SELECT '2' course_id, 'john' student_name FROM DUAL
  5           UNION ALL
  6           SELECT '1' course_id, 'peter' student_name FROM DUAL
  7           UNION ALL
  8           SELECT '2' course_id, 'peter' student_name FROM DUAL
  9           UNION ALL
10           SELECT '3' course_id, 'king' student_name FROM DUAL
11           UNION ALL
12           SELECT '4' course_id, 'king' student_name FROM DUAL),
13       r
14       AS (SELECT     student_name, SUM (POWER ( 2, course_id)) val
15               FROM   T
16           GROUP BY   student_name)
17  SELECT   DISTINCT student_name NAME
18    FROM   r
19   WHERE   EXISTS
20              (SELECT     'x'
21                   FROM   r r1
22                  WHERE   r1.val = r.val
23               GROUP BY   val
24                 HAVING   COUNT (*) > 1);
NAME
john
peterEdited by: G. on Feb 24, 2011 2:09 PM

Similar Messages

  • In audit few statemntns SQL statements is not populating

    Hi,
    I enable audit,for few (SELECT,CREATE TABLE)statements audit not populating sqltext in sys.aud$.But i can see few more SELECT&CREATE TABLE activityit populates SQLTEXT.
    if it not populates sql text ,what ll be the reason behind this?

    Thank you for quick reply, Joe!
    Yes, I meant the second option with '%' symbols but still I get incorrect results. Seems that OpenSQL layer ignores the 'NOT LIKE' criterias. Any other ideas?
    I'm pasting you the log I have with the JPQL and the prepared SQL queries
    <query jpql="select distinct e, e.time.srvrStrInitTime from SlAutoGeneral e where e.status not like :status order by e.time.srvrStrInitTime desc ">
        <executeQuery>
            <prepare sql="SELECT DISTINCT E.ID E_ID_id,E.STATUS E_STATUS_status,E.SYNTH_SUBJECT E_SYNTH_SUBJECT_synthSubject,
              ALIAS_1.SRVR_STR_INIT_TIME DISPLAY_2
              FROM SL_AUTO_TIME ALIAS_1, SL_AUTO_GENERAL E WHERE ALIAS_1.ID = E.ID AND E.STATUS NOT LIKE ? ORDER BY DISPLAY_2 DESC"/>
    Best regards,
    Martin

  • Tricky SQL statement

    Hi,
    I've got 3 columns X,Y & Z.
    Each column can have the values 'A', 'B' or NULL.
    If 2 out of 3 have an 'A' I want to get 'TEXT1', if 2 out of 3 have a 'B' I want to get 'TEXT2' in all other cases I want to 'TEXT3'.
    I'm using 8.1.7.0.0 and only direct SQL is allowed (so no own functions or procedure's).
    Can anybody help me please?

    create table test(x varchar2(1), y varchar2(1), z varchar2(1));
    delete from test ;
    insert into test values('A', 'A', 'A');
    insert into test values('A', 'A', 'B');
    insert into test values('A', 'A', null);
    insert into test values('A', 'B', 'A');
    insert into test values('A', 'B', 'B');
    insert into test values('A', 'B', null);
    select
    min(decode (zcount,2,decode(zcol,'A','TEXT1','B','TEXT2','TEXT3') ,'TEXT3'))
    from
    (select zcol, count(*) zcount, zrowid
    from
    (select x zcol , rowid zrowid from test
    union all
    select y zcol , rowid zrowid from test
    union all
    select z zcol , rowid zrowid from test
    group by zcol, zrowid
    ) AAA
    group by zrowid
    TEXT3
    TEXT1
    TEXT1
    TEXT1
    TEXT2
    TEXT3

  • SQL statement - tricky search problem

    Hi,
    I am working in asp and use an Access db. I have a database
    with 500 shops around the world, the table contains among other
    things shop name, country and region (Europe, Asia etc). Then a
    search page with dropdown lists, one for Region and one for
    Country. Here is the problem, which seems easy first, but I really
    can´t get the sql statement to do what I want:
    The Region list has the following values:
    Any region
    Europe
    Asia
    etc
    The country list has te following values:
    Any country
    Sweden
    Germany
    USA
    etc
    Ok, so the problem is if the user choose "Any Region" and
    "Any Country" all shops should come up. "Europe" and "Any Country"
    should give all shops in Europe". "Any region" and "Sweden" should
    pull up ONLY shops in Sweden. "Europe" and "Sweden" should also
    pull up shops in Sweden only.
    Now you start see the problem. I have laborated with AND resp
    OR statments and also % resp xyz in the "Any Country" and "Any
    Region" values.
    Any help would be highly appreciated! Thanks!!

    Thank Manish,
    Could you tell me how to restrict in following codes?
    select
    e.EQUIPMENT_ID,
    e.HOST_NAME,
    e.SERIAL_NUMBER,
    e.CITY,
    e.ROOM,
    e.RACK,
    e.CR_DT,
    e.CR_USR,
    e.LM_USR,
    e.LM_DT,
    e.TASK_TASK_ID
    from SVR_EQUIPMENT e
    where
    instr(upper(e.SERIAL_NUMBER),upper(nvl(:P1_REPORT_SEARCH,e.SERIAL_NUMBER))) > 0 and
    instr(upper(e.CITY),upper(nvl(:P1_REPORT_SEARCH,e.CITY))) > 0 and
    instr(upper(e.CR_USR),upper(nvl(:P1_REPORT_SEARCH,e.CR_USR))) > 0 or
    instr(upper(e.LM_USR),upper(nvl(:P1_REPORT_SEARCH,e.LM_USR))) > 0
    Thanks for all again,
    Sam

  • How to run a SQL statement which is stored inside an SQL Table

    Hello,
    If anyone please help me with the following problem I would be forever grateful
    I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
    Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
    Thanks in advance!
    This is how it looks like more or less:
    Displaying result for:
    SELECT TRIM(OBJ_VALU_TXT)
    FROM   OBJ_VALU_DOC
    WHERE  OBJECT_TYPE  = 'FLD'
      AND  OBJECT_CODE  = 15443
      AND  OBJ_VALU_CD  = 'ACR'
    ORDER BYDOC_SEQ_NO
    00001                                                            
    SELECT
    VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
    FROM RECEIPT
    WHERE (RECEIPT_NO BETWEEN
    :OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
    (RECEIPT_NO > :OUT-COMP-FACTOR AND
    :OUT-TO-NUMBER = 0)

    Here's a demo of your requirement.
    create table t ( col1 varchar2(200));
    table created
    insert into t values('select * from dual');
    1 row inserted
    declare
    v_col varchar2(200);
    v_val varchar2(200);
    begin
    select col1 into v_col from t;
    execute immediate v_col into v_val;
    dbms_output.put_line(v_val);
    end;
    X
    Using into clause, you can use as many variables as required. But the basic approach reamins the same.
    But storing SQL in DB is not an efficient design.
    Ishan

  • SAP BW 3.5 "Error in SQL Statement: DBIF_RSQL_INVALID_RSQL" in Infospoke

    Hi ,
    I am working on SAP BW 3.5.
    while downloading the records through infospoke and giving them to the Application server side, I am getting an error  "Error in SQL Statement: DBIF_RSQL_INVALID_RSQL".
    Daily the Infospoke runs on delta mode. But for downloading of few records i have deactivated the delta and changed it in to Full mode. After downloading the data I again Activated the delta.but while Executing on Background mode I am getting an error mentioned above.
    can anyone please suggest a solution for resolving this error?
    Thanks in advance.
    Santosh.

    Hi:
    Did you do some recent change in the objects?. I face sometimes this error and it is due to misalignment among the objects in a data flow (cubes, DSOs, transformations, DTPs, etc.).
    What you can do is activate everything again.
    Best regards.

  • Group by in a SQL statement

    I have this SQL Statement
    SELECT PTE.PLT_SHORT_NAME PLT_SHORT_NAME,
    COUNT ( * ) SEGMENTS,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) SEGMENTS_COMPLY,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , 1 , NULL ) ) SEGMENTS_NO_COMPLY,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_GANADO,
    ( ( COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) / COUNT ( * ) ) * 100 ) || '%' COMPLY_PERCENT,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_PERDIDO,
    ( SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) + SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) ) DIFERENCIA
    FROM PLT_TRN_EVALS PTE,
    TRN_EVALS TE,
    TRN_EVENT_TIMES_HEADERS TETH
    WHERE ( /* CG$MDTU_QWC_START Q_1.PTE */
    (PTE.PLT_SHORT_NAME IS NOT NULL AND PTE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.PTE */
    ) AND
    ( /* CG$MDTU_QWC_START Q_1.TE */
    (TE.TYP = 'SEG' AND TE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.TE */
    ) AND
    PTE.TE_SEQ = TE.SEQ AND
    ( /* CG$MDTU_QWC_START Q_1.TETH */
    (TETH.DELETED = 'N' AND TETH.SCHED_DATE BETWEEN :P_DATE_FROM AND :P_DATE_TO)
    /* CG$MDTU_QWC_END Q_1.TETH */
    ) AND
    TE.TETH_SEQ = TETH.SEQ
    GROUP BY PTE.PLT_SHORT_NAME
    And I would like to know, how can I include the GROUP BY in order to generate

    I think your question got cut off. What are you trying to generate with this SQL? I should say in advance that Oracle Designer has very few places where you can enter a SELECT command directly. You can usually get it to generate what you need by choosing the correct Table Definition (or View Definition) usages, choosing the display columns you want, and adding WHERE clauses and GROUP BY columns.
    With something as complex as your Statement, I would probably consider creating a View, then use the View in modules.

  • Writing mulitple sql statements in 1 stored procedure

    Hi all, can i know how to create mulitple sql statements in 1 stored procedure??
    Eg the first sql statement will generate few results and my second sql statement will based on the first statement result to execute its second results and my third sql statements will on the second results to generate the final results which will be passed back to jsp pages as a resultset??
    For the time being, i only know how to create a single sql statement in one stored procedure..i had surf through the oracle website but cant find any solution. Can anyone help me?? Samples or links to any website will do.. Thanks alot...

    Hi Irene,
    If I understand your question correctly, then I have already written
    a similar (PL/SQL) stored procedure without any problems.
    However, I do think your question is more suited to the following
    forum:
    http://forums.oracle.com/forums/forum.jsp?id=478021
    I also think it will help others to answer your question if you
    include the following information:
    1. Version of Oracle you are using.
    2. The error message you are getting.
    3. The part of your code that is causing the problem.
    Also, have you looked at the following web sites?
    http://asktom.oracle.com
    http://metalink.oracle.com
    Good Luck,
    Avi.

  • Converting SQL statements from MS server 2000 to Oracle 10g

    We are moving over from MS server 2000 to Oracle 10g as our database for Peoplesoft system.
    There are several embedded SQL statements that I need to investigate to see what needs converting.
    So far I can see a need to convert the following:
    Dates.     GetDate() to ?
    Outer joins. *= to LEFT OUTER JOIN
    Has anyone else done a similar exercise and what other functions do I need to convert?
    Thanks.

    Hello
    A quick google search (http://www.google.co.uk/search?hl=en&q=ms+sql+server+oracle+differences&spell=1)
    came up with this:
    http://dba-oracle.com/oracle_news/2005_12_16_sql_syntax_differences.htm
    There's a quite a few more sites listed.
    HTH
    David

  • Performance of SQL-Statements in Reports

    Hi
    I have a very complex SQL-Statement in a Region-Report with Items in the where-clause:
    select ....
    where  idt_1 like :P1_IDT
    and    idt_2 like :P1_IDT2
    ...it generates 100 Million records in the Temp Tablespace and produce either a timeout or an error-message that the Temp-Tablespace is not big enough.
    If I replace the Items with real values it runs in a few seconds in the SQL-Workshop.
    select ....
    where  idt_1 like 10
    and    idt_2 like 11
    ...If I use the Region-Type based "PL/SQL Function Body returning SQL Statement" and generate the Statment like this:
    v_statment:= 'select ... where idt_1 like ' || :P1_IDT;
    return v_statment;it runs in a few seconds too.
    Any explanations?
    Regards, Juergen

    Jürgen,
    John's recommendation is sound. Your last two examples ultimately use literal values in your query statement (that is, the query optimizer can use these values to determine the optimal query plan). The query plans for the last two queries may be entirely different than what was generated for your first query.
    Additionally, if the selectivity of your first query shifted dramatically across subsequent executions, the query plan initially generated may not be suitable again.
    Examining the tkprof output should elucidate all of this.
    Joel

  • Using a string variable as a query SQL statement

    I want to construct a custom SQL statement in a string var, then use that var in the cfquery statement.  What is the proper syntax?  Here is my feeble attempt:
      <cffunction ...>
      <cfset var sql_txt="">
            <cfquery name="qSBJs" datasource="cfBAA_odbc">
                "#sql_txt#"
            </cfquery>
        <cfreturn qSBJs>
    I've tried using no " or # or just # or just " but nothing works.
    what about:
            <cfquery name="qSBJs" datasource="cfBAA_odbc" sql="#sql_txt#">
            </cfquery>
    nope.  I wish there was a sql property I could fill *before* the execution of the query.  Any suggestions?

    Hi Adam, and/or anyone who may have a few minutes to check this... I got the following code to work.  It calls the getSBJs function from Flash Builder 4.  I get the correct result set back.  Long table names are replaced with short abreviations.  Note that some local vars are declared but not used in the following example. I will use them in the future versions of this same code.  Since I will in the future, like a donkey, mindlessly use this same method for all my queries, it would be much appreciated if I could get a guru to check this code for:
    -Pure idiocy
    -Mild insanity
    -SQL injection vulnerability
    -Memory leakage
    -Scope dangers
    (ignore emoticons, see the underlying text)
        <cffunction name="AbrvTblNms" output="false" returntype="string" >
            <cfargument name="txt" type="string" required="true" />
            <cfset var qAbrvs="">
            <cfset var output_str="#ARGUMENTS.txt#">
            <cfquery name="qAbrvs" datasource="cfBAA_odbc" result="rsltAbrvs">
                SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
            </cfquery>
        <cfloop query="qAbrvs">
                <cfset output_str = Replace(output_str, '[' & qAbrvs.TBL_NM & ']', qAbrvs.ABRV, "ALL")>
        </cfloop>
            <cfreturn output_str>
        </cffunction>
        <!--- Fetch a list photo subjects whose records contain the given search word(s) --->
        <cffunction name="getSBJs" output="false" access="remote" returntype="any" >
            <cfargument name="srch_val" type="string" required="true" />
            <cfset var qSBJs="">
            <cfset var sql_txt="">
            <cfset var whr=""> 
            <cfset var b=False>
            <cfset var in_txt="">
            <cfset var fm_dt="">
            <cfset var to_dt="">
            <cfset var on_dt="">
            <cfset var pht="">
            <cfset var srch_str="">
            <cfset var srch_trm="">
            <!--- Transfer the srch_val to a local variable for further manipulation --->
            <cfset srch_str = "#ARGUMENTS.srch_val#">
            <!---
                An empty search term argument is handled by the BAA FlashBuilder front end.  We test for it again here,
                and substitute a dummy value, in case this function is called by something other than the intended
                FlashBuilder front end, and that front end doesn't protect us from an empty search term argument.
                Remember that we must still "hand back" a valid query structure to avoid causing a data type error
                in the calling function, so we search for a dummy value that will allow the query to proceed but is
                guaranteed to return an empty result set.  If the srch_val argument is not empty, transfer the value of
                the srch_str local variable to the srch_trm local variable.
            --->
            <cfif Not (Len(srch_str))>
                <cfset srch_str = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">
            </cfif>
            <cfset srch_trm = "#srch_str#">
            <cfset sql_txt =
                "SELECT DISTINCT
                  [BAA_SBJ].SRC_SYS_NM, [BAA_SBJ].SRC_SYS_GUID, [BAA_SBJ].OBJ_GUID, [BAA_SBJ].SBJ_NM, [BAA_SBJ].SBJ_DOB, [BAA_SBJ].SBJ_ID, [BAA_SBJ].NOTE, [BAA_SBJ].CDT, [BAA_SBJ].CTM, [BAA_SBJ].CBY, [BAA_SBJ].MDT, [BAA_SBJ].MTM, [BAA_SBJ].MBY
                FROM
                  BAA_SBJ [BAA_SBJ]
                  LEFT JOIN BAA_SES [BAA_SES] ON [BAA_SES].PAR_GUID = [BAA_SBJ].OBJ_GUID
                  LEFT JOIN BAA_IMG [BAA_IMG] ON [BAA_IMG].PAR_GUID = [BAA_SES].OBJ_GUID
                WHERE [WHERE_CLAUSE] ORDER BY [BAA_SBJ].SBJ_NM">
            <cfset whr = "([BAA_SBJ].SBJ_NM CONTAINING TRIM( rm_srch_trm1 ) OR " &
                    "[BAA_SBJ].NOTE CONTAINING TRIM(:prm_srch_trm2 ) OR " &
                    "[BAA_SBJ].SBJ_DOB CONTAINING TRIM(:prm_srch_trm3 ) OR " &
                    "[BAA_SES].SES_TYP CONTAINING TRIM(:prm_srch_trm4 ) OR " &
                    "[BAA_SES].NOTE CONTAINING TRIM(:prm_srch_trm5 ) OR " &
                    "[BAA_IMG].NOTE CONTAINING TRIM(:prm_srch_trm6 ))">
            <cfset sql_txt = Replace(sql_txt,"[WHERE_CLAUSE]", "#whr#", "ALL")>
            <cfset sql_txt = AbrvTblNms(sql_txt)>
        <!--- Through experimentation, I learned that each occurance of a param must be uniquely named.
                  It would be very handy, if the param value was applied to *all* occurances of the param.
                        That way, I could get away with using one .addParam line instead of 6 --->
            <cfscript>
            queryService = new query();
            queryService.setDatasource("cfBAA_odbc");
            queryService.setName("qSBJs");
            queryService.setAttributes(sql="#sql_txt#");
            queryService.addParam(name="prm_srch_trm1", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm2", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm3", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm4", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm5", value="#srch_trm#", cfsqltype="VARCHAR");
            queryService.addParam(name="prm_srch_trm6", value="#srch_trm#", cfsqltype="VARCHAR");
            result = queryService.execute();
            qSBJs = result.getResult();
            </cfscript>       
            <!--- <cfquery name="qSBJs" datasource="cfBAA_odbc">
            </cffunction>
            </cfquery> --->
            <cfreturn qSBJs>
        </cffunction>
    THANKS TO ADAM AND DAN FOR HELPIMG ME GET THIS FAR!  Now, don't let me embarass you by doing something dum and giving you "credit", if you see me doing something dum above.  Thanks!

  • APP-ALR-04106: Please correct the user-defined SQL statement for this alert

    Hi All,
    I have created an alert for engineering module in R12. It got tested and was working fine. when the user testing it, while trigger the alert getting the error, "APP-ALR-04106: Please correct the user-defined SQL statement for this alert".
    when verified the alert, it got verified and ran also. It parsed the query successfully and when run it fetched few records.
    Need help in resolving the issue.
    Thanks in advance.
    Regards,
    sri
    Edited by: user10939296 on Jan 18, 2010 1:16 AM

    Hi Sri;
    I have already gone through the Note: 948037.1. But this note is related to 11i. The solution provided in the Note is for 11i.
    I am facing this issue in R12. Is this patch applicable to R12?I belive its not. But u can check Solution part 4 for your instance, at least it can give you idea. The other note in metalink related bug and all for R11 too.
    I belive its better way to rise Sr while waiting other forum user response to that thread
    Regard
    Helios

  • Native SQL Statement help!

    Hi guys,
    I need some help here.
    I have a requirement to select from Microsoft SQL database
    Question
    How do I select with RANGE internal tables? As you can see, I have 4 range tables for this.
    BElow are my codes
    EXEC SQL.
        CONNECT TO 'CONNECTION_NAME'
      ENDEXEC.
      IF sy-subrc <> 0.
        MESSAGE 'Unable to connect to CONNECTION_NAME' TYPE 'E' DISPLAY LIKE 'I'.
        RETURN.
      ENDIF.
    * Define database cursor
      EXEC SQL.
        OPEN dbcur FOR
                SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
                       qty, zopcd, bstnk, wekunnr
                  FROM <TABLE_NAME>
                 WHERE month IN i_month
                   AND yyear IN i_year
                   AND kunnr IN i_kunnr
                   AND bstnk IN i_bstnk
      ENDEXEC.
    * Fill itab
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :l_dest-name1,
                                :l_dest-zvctk,
                                :l_dest-kunnr,
                                :l_dest-yyear,
                                :l_dest-mmonth,
                                :l_dest-matnr,
                                :l_dest-qty,
                                :l_dest-zopcd,
                                :l_dest-bstnk,
                                :l_dest-wekunnr
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          APPEND l_dest TO it_dest.
        ENDIF.
      ENDDO.
    its giving me a shortdump
    >>>>>     OPEN dbcur FOR
       35             SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
       36                    qty, zopcd, bstnk, wekunnr
       37               FROM v_promise_sa
       38              WHERE month IN i_month[]
       39                AND yyear IN i_year[]
       40                AND kunnr IN i_kunnr[]
       41                AND bstnk IN i_bstnk[]
    Error message:
    Database error text........: "[Microsoft][SQL Server Native Client 10.0][SQL
    Server]Incorrect syntax near 'i_month'."
    Database error code........: 102
    Triggering SQL statement...: "SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
    qty, zopcd, bstnk, wekunnr FROM <TABLE_NAME> WHERE month IN i_month[] AND
    yyear IN i_year[] AND kunnr IN i_kunnr[] AND bstnk IN i_bstnk[]"
    Internal call code.........: "[DBDS/NEW DSQL]"
    Please check the entries in the system log (Transaction SM21).
    Can anyone guide me? If I do not enter the where clause, it is selecting fine.
    Appreciate it guys! Thanks in advance!

    lol, Come guys, don't judge me by just my forum nick man. It was just something random during registration a few years back...was indeed new in ABAP language :P
    But anyway, the table v_promimse_sa is not in the DDIC, its some microsoft MYSQL database or something.
    anyway what I did now:
    EXEC SQL.
        CONNECT TO 'MSSQL_PROMISE'
      ENDEXEC.
      IF sy-subrc <> 0.
        MESSAGE 'Unable to connect to MSSQL_PROMISE' TYPE 'E' DISPLAY LIKE 'I'.
        RETURN.
      ENDIF.
    * Define database cursor
      EXEC SQL.
        OPEN dbcur FOR
                SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
                       qty, zopcd, bstnk, wekunnr
                  FROM v_promise_sa
                 WHERE mmonth = :i_month
                   AND yyear  = :i_year
    *               AND ( kunnr BETWEEN :i_kunnr-low AND :i_kunnr-high )
    *               AND ( bstnk BETWEEN :i_bstnk-low AND :i_bstnk-high )
      ENDEXEC.
    * Fill itab
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :l_dest-name1,
                                :l_dest-zvctk,
                                :l_dest-kunnr,
                                :l_dest-yyear,
                                :l_dest-mmonth,
                                :l_dest-matnr,
                                :l_dest-qty,
                                :l_dest-zopcd,
                                :l_dest-bstnk,
                                :l_dest-wekunnr
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          APPEND l_dest TO it_dest.
        ENDIF.
      ENDDO.
    *    EXEC SQL.
    *      CLOSE dbcur
    *    ENDEXEC.
      DELETE it_dest WHERE kunnr NOT IN i_kunnr
                       AND bstnk NOT IN i_bstnk.
    Well, after checking with the functional person, there are only 3 records so I guess the selection + filtering is working.

  • How to monitor worst performing sql statements

    Hi,
    I am new to oracle 9i release 2. I come from the Windows world, where we used sql server.
    When we performanced tested our product, we always monitor the worst performaning sql statement using the sql profiler. At the end of a 24 hour test, the profiler will list the sql statement with the longest execution time. What is the equivalent Oracle 9i tools that will allow me to monitor the worst performaning sql during a test that lasts between 10 to 24 hours?
    Thanks,
    Paul0al

    Besides statspack and OEM you have a few other options.
    If an SQL statement had been identified as performing poorly or a job that you can extract the SQL from then you have the option of explaining all the SQL statements and just reviewing the plans for reasonableness. You can also trace actual execution of the task or individual statemnts (alter session set sql_trace = true for basic 10046 event).
    When the SQL has not been identified in advance you can query the shared pool SQL areas for SQL statements that have relatively high physical, logical, or combined IO counts. Then you can perform tuning activities for these statements.
    HTH -- Mark D Powell --

  • Tracing / Profiling SQL statements in Sybase

    Hi Guys, I would like to capture the SQL statements that have been fired from a web app (bit like SQL Server's profiler). Is there such a tool / facility?Please note that I cannot use dbcc commands like traceon as DBA's wont grant me sa rights (in dev...crazy eh).
    Is there any easy way of doing this?
    Thanks

    General comment about MDA monitoring (tools) ...
    If the local DBAs don't have any tools for monitoring MDA tables there are a few 3rd party tools that can provide MDA monitoring (ie, little/no programming required by the local DBAs).
    Most of these 3rd party tools cost $$ to purchase, and each one has its strengths and weaknesses.
    There is one 3rd party tool (that I know of) that is free, highly configurable, and IMHO does a very good job at collecting/presenting MDA data (especially from a historical perspective): ASEMON
    I personally:
    - use ASEMON for P&T work
    - install/configure ASEMON at my clients when a) they don't already have a MDA monitoring capability or b) they want to free up the $$ they're paying for some other 3rd party tool
    NOTE: As Mike has pointed out, MDA collections can grow quite large and rather quickly.  This is true with ASEMON, too.

Maybe you are looking for

  • Hp DVD RW AD-7251H5 Booktype

    Hello, does anyone know how i can change the Booktype on a hp DVD RW AD-7251H5 ? This question was solved. View Solution.

  • BI answers functions

    Hi is there any documentation about the functions in bi answers , I got trouble finding out how to calculate a percentage, I finally found this : measure/sum(measure by column). I have trouble now using other functions , if any doc is available pleas

  • FBV0 - Screen variant

    Hi , We have merged 5 production system in one client (SLO). I created screen variants for FB50, FB60 , FB75 , and Fv60 . I assigned it to the user group and it is working fine in merged system(now production system) even after assigning the FBv0 tra

  • Safari 5.05 in Lion

    I just updated to Lion but don't seem to have the new Safari features described in the Lion literature.  I checked my version (5.05) and found a newer Safari (5.1) on apple.com.  Running the update I get a message that I need Mac 10.6.  Basically, th

  • MacBook Pro Retina 13' 2015 [MF840] (rattle inside macbook)

    Hey people plz help! I have a prolem with my MacBook Pro MF840 Searching the way to solve my problem I visited few apple authorized stores in Ukraine, and I asked if I can try to shake new models MacBook Pro 13' (MF839, MF840, MF841) to find out if t