Delete query using inner join

I need to delete records from a table using inner join from other tables. See below for the table structure and records.
CREATE TABLE STUDENT (ROLL_NO NUMBER(10),NAME VARCHAR2(100),DEPT_NO NUMBER(10),JOIN_DATE DATE);
CREATE TABLE DEPART (DEPT_NO NUMBER(10), DEPT_NAME VARCHAR2(100));
CREATE TABLE ACTIVE_DEPT (DEPT_NO NUMBER(10), IS_ACTIVE VARCHAR2(1));
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(1,'SAM',10,SYSDATE-10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(2,'ALEX',10,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(3,'FRANK',20,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(4,'WAYNE',20,SYSDATE+1);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(5,'KRUL',30,SYSDATE -10);
INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(6,'ALICE',40,SYSDATE -10);
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (10,'DEPT1');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (20,'DEPT2');
INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (30,'DEPT3');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (10,'Y');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (20,'N');
INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (30,'Y');
DELETE FROM STUDENT WHERE (STUDENT.DEPT_NO) IN (SELECT D.dept_no FROM DEPART D,ACTIVE_DEPT AD WHERE D.DEPT_NO = AD.DEPT_NO AND AD.IS_ACTIVE = 'N');The above delete query will delete two records from the STUDENT table. Now i want to include another condition say, join_date should be a past date (join_date < trunc(sysdate)).
How to include this condition in the above delete statement. I know i can do this using a subquery but i wont prefer that option. Basically i don't have much idea about join in delete statements.
Please help.

Is this you need ?
DELETE FROM student WHERE join_date < TRUNC(SYSDATE)
                                        AND student.dept_no IN (SELECT D.dept_no
                                                                  FROM depart d,active_dept ad
                                                                 WHERE d.dept_no = ad.dept_no AND ad.is_active = 'N');Only one record is deleted. -> 3,'FRANK',20,SYSDATE -10
>
Balaji      wrote:
Yes. But here we are getting the dept_no from the sub query, is there a better way to achieve this without sub query?
>
As far I know you need to have sub query in this case.
You can close this thread if answered. If you have any further queries please post it so that someone can help you.
Edited by: Lokanath Giri on २० मार्च, २०१२ ५:०५ अपराह्न

Similar Messages

  • Issue when suming the field in Select query using inner join

    Hi All,
    SELECT A~OI_SHNUM
           A~FORWAGENT        
           A~ROUTE
           A~SHTYP
           A~DTSHP_EACT
           A~/BIC/GTCLICENS
           A~/BIC/GTCADD04
           A~COMP_CODE
           SUM( C~GRS_WGT_DL )
           C~UNIT_OF_WT
      INTO TABLE I_LAYONE
      FROM ( ( /BIC/ANTCD000200 AS A
      INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
      INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB ).
    I need to sum the field C~GRS_WGT_DL
    While compiling it show the error given below
    The field "C~UNIT_OF_WT" from the SELECT list is is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is "C~UNIT_OF_W
    with regards,
    Thambe

    Hi,
    Try the following SQL statement. Hope it helps you.
    SELECT A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE
    SUM( C~GRS_WGT_DL )
    C~UNIT_OF_WT
    INTO TABLE I_LAYONE
    FROM ( ( /BIC/ANTCD000200 AS A
    INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
    INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB )
    GROUP BY
    A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE.
    Murthy.

  • Why can't i use "INNER JOIN" in a query for SQL Server with JDBC??????

    Hi,
    I'm trying to execute some SQL queries and I just don't understand what's wrong.
    I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
    I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
    Error occurs when executeQuery() is called.... not prepareStatement().... ??????
    Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
    Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
    PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
    ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
    So much tahnks in advance,

    That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
    Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
    I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
    ( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
    thanks for reply.

  • Query on Inner Joins

    Hi experts,
    I want to join the following fields balm, comh, comhr, balhdr, edidc.
    I don't have common fields comhr and balhdr.
    I have written an SQL query like this, will it work? what about performance
    Please let me know.
      select comh~msid
             comh~mscla
             comh~sedat
             comh~seuzt
             comhr~bid
             balhdr~extnumber
             balm~lognumber
             balm~msgid
             balm~msgv1
             balm~msgv2
             balm~msgv4
        into corresponding fields of
       table i_comhr
        from comh
        inner join comhr on comhmsid = comhrmsid
        inner join balhdr on comhmsid = balhdrextnumber
        inner join balm on balhdrlognumber = balmlognumber
        where comh~sedat in credatc
          and comh~seuzt in cretimc
          and comh~werk in werk
          and comh~source in source
          and comh~mscla in mscla
          and comh~errkz = errkz
          and comh~tstkz in tstkz.
    thanx,
    jeevi.

    Hi,
    Inner join can be used on matching keys only then it will display relevent data otherwise if keys are not matching it will not select the data.
    Performance wise it is not at all recommeded to join mistmatch keys.
    inseead u can do one thing , select data from comh and comhr into one itab using inner join and balhdr balm in other itab using inner join then u can read both itabs and can update data, anyway there u may need one link bet itabs that u can use for select stmt.
    Hope following program will help u ...
    Check this program,similar requirement.On click it is leading to transaction and bdc prcoess goes on.
    * INCLUDE Z48M_KB11N_MAN_POST_F01 *
    *& Form GET_DATA
    * text
    * --> p1 text
    * <-- p2 text
    FORM GET_DATA.
    DATA : L_AMOUNT LIKE EKPO-MENGE.
    DATA : LV_POSID TYPE PRPS-PSPNR.
    DATA : LV_POSID_OLD TYPE PS_POSID.
    DATA : LV_POSID_NEW TYPE PS_POSID.
    DATA : LV_EBELN TYPE EKPO-EBELN,
    LV_EBELP TYPE EKPO-EBELP,
    LV_MESG_ID(20) TYPE C,
    LV_MESG_NO(3) TYPE C.
    CLEAR : G_T_BALHDR,G_T_BALHDR_FINAL.
    REFRESH : G_T_BALHDR,G_T_BALHDR_FINAL.
    *To get the PO num,item,mesg id,mesg no and text of mesg.
    SELECT *
    FROM BALHDR
    INTO CORRESPONDING FIELDS OF TABLE G_T_BALHDR
    WHERE OBJECT EQ 'Z48MMIGO' AND
    SUBOBJECT EQ 'ZKB11N'.
    IF NOT G_T_BALHDR[] IS INITIAL.
    LOOP AT G_T_BALHDR.
    CLEAR : G_T_T100.
    REFRESH : G_T_T100.
    CLEAR : LV_EBELN,LV_EBELP,LV_MESG_ID,LV_MESG_NO.
    LV_EBELN = G_T_BALHDR-EXTNUMBER(10).
    LV_EBELP = G_T_BALHDR-EXTNUMBER+13(5).
    LV_MESG_ID = G_T_BALHDR-EXTNUMBER+19(2).
    LV_MESG_NO = G_T_BALHDR-EXTNUMBER+22(3).
    SELECT SINGLE *
    FROM T100
    INTO CORRESPONDING FIELDS OF G_T_T100
    WHERE SPRSL = SY-LANGU AND
    ARBGB = LV_MESG_ID AND
    MSGNR = LV_MESG_NO.
    IF SY-SUBRC = 0.
    G_T_BALHDR_FINAL-LOGNUM = G_T_BALHDR-LOGNUMBER.
    G_T_BALHDR_FINAL-OBJECT = G_T_BALHDR-OBJECT.
    G_T_BALHDR_FINAL-SUBOBJECT = G_T_BALHDR-SUBOBJECT.
    G_T_BALHDR_FINAL-EBELN = LV_EBELN.
    G_T_BALHDR_FINAL-EBELP = LV_EBELP.
    G_T_BALHDR_FINAL-MESG = G_T_T100-TEXT.
    APPEND G_T_BALHDR_FINAL.
    ENDIF.
    ENDLOOP.
    ENDIF.
    IF NOT G_T_BALHDR_FINAL[] IS INITIAL.
    CLEAR : G_T_EKPO.
    REFRESH : G_T_EKPO.
    *To get the amount,currency and new a/c assignment.
    SELECT A~EBELN A~LIFNR A~WAERS B~EBELP B~NETPR B~MENGE B~MEINS
    C~PS_PSP_PNR
    INTO CORRESPONDING FIELDS OF TABLE G_T_EKPO
    FROM ( EKKO AS A INNER JOIN EKPO AS B
    ON A~EBELN = B~EBELN
    INNER JOIN EKKN AS C
    ON B~EBELN = C~EBELN AND
    B~EBELP = C~EBELP )
    FOR ALL ENTRIES IN G_T_BALHDR_FINAL
    WHERE A~EBELN = G_T_BALHDR_FINAL-EBELN AND
    B~EBELP = G_T_BALHDR_FINAL-EBELP.
    ENDIF.
    IF NOT G_T_EKPO[] IS INITIAL.
    CLEAR : G_T_PO_LIFNR.
    REFRESH : G_T_PO_LIFNR.
    *To get the Cost element.
    SELECT *
    FROM Z48M_IN_PO_LIFNR
    INTO CORRESPONDING FIELDS OF TABLE G_T_PO_LIFNR
    FOR ALL ENTRIES IN G_T_EKPO
    WHERE LIFNR = G_T_EKPO-LIFNR AND
    PRJKT = 'X'.
    ENDIF.
    SORT G_T_BALHDR_FINAL BY EBELN EBELP.
    CLEAR : G_T_FINAL.
    REFRESH : G_T_FINAL.
    LOOP AT G_T_BALHDR_FINAL.
    SORT G_T_EKPO BY EBELN EBELP.
    READ TABLE G_T_EKPO WITH KEY EBELN = G_T_BALHDR_FINAL-EBELN
    EBELP = G_T_BALHDR_FINAL-EBELP
    BINARY SEARCH.
    IF SY-SUBRC = 0.
    CLEAR : L_AMOUNT.
    L_AMOUNT = G_T_EKPO-NETPR * G_T_EKPO-MENGE.
    CLEAR : LV_POSID_NEW.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
    EXPORTING
    INPUT = G_T_EKPO-PS_PSP_PNR
    IMPORTING
    OUTPUT = LV_POSID_NEW.
    READ TABLE G_T_PO_LIFNR WITH KEY LIFNR = G_T_EKPO-LIFNR
    PRJKT = 'X'
    BINARY SEARCH.
    IF SY-SUBRC = 0.
    CLEAR : LV_POSID.
    *To get the old a/c assignment.
    SELECT SINGLE PSPNR
    INTO LV_POSID
    FROM PRPS
    WHERE PSPHI EQ G_T_PO_LIFNR-PSPNR AND
    STUFE EQ 1.
    IF SY-SUBRC = 0.
    CLEAR : LV_POSID_OLD.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
    EXPORTING
    INPUT = LV_POSID
    IMPORTING
    OUTPUT = LV_POSID_OLD.
    *Fill the final tab.
    G_T_FINAL-LOGNUM = G_T_BALHDR_FINAL-LOGNUM.
    G_T_FINAL-OBJECT = G_T_BALHDR_FINAL-OBJECT.
    G_T_FINAL-SUBOBJECT = G_T_BALHDR_FINAL-SUBOBJECT.
    G_T_FINAL-EBELN = G_T_EKPO-EBELN.
    G_T_FINAL-EBELP = G_T_EKPO-EBELP.
    G_T_FINAL-NETPR = G_T_EKPO-NETPR.
    G_T_FINAL-MENGE = G_T_EKPO-MENGE.
    WRITE L_AMOUNT UNIT G_T_EKPO-MEINS TO G_T_FINAL-AMOUNT.
    G_T_FINAL-WAERS = G_T_EKPO-WAERS.
    G_T_FINAL-KSTAR = G_T_PO_LIFNR-KSTAR.
    G_T_FINAL-POSID_OLD = LV_POSID_OLD.
    G_T_FINAL-POSID_NEW = LV_POSID_NEW.
    G_T_FINAL-MESG = G_T_BALHDR_FINAL-MESG.
    APPEND G_T_FINAL.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_DATA
    *& Form DISPLAY_DATA
    * text
    * --> p1 text
    * <-- p2 text
    FORM DISPLAY_DATA.
    IF G_T_FINAL[] IS INITIAL.
    MESSAGE S114(KB).
    EXIT.
    ENDIF.
    * Populating the field catalog to the alv list
    PERFORM FIELDCAT_POPULATION.
    * Displaying report in ALV list format
    PERFORM ALV_DISPLAY.
    ENDFORM. " DISPLAY_DATA
    *& Form FIELDCAT_POPULATION
    * text
    * --> p1 text
    * <-- p2 text
    FORM FIELDCAT_POPULATION.
    DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV. " For column heading
    CLEAR : G_T_FIELDCAT,
    G_T_FIELDCAT[].
    * PO Number
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'EBELN'.
    L_FIELDCAT-SELTEXT_M = TEXT-001.
    L_FIELDCAT-COL_POS = 1.
    L_FIELDCAT-KEY = 'X'.
    L_FIELDCAT-OUTPUTLEN = 15.
    L_FIELDCAT-HOTSPOT = 'X'.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    * PO item
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'EBELP'.
    L_FIELDCAT-SELTEXT_M = TEXT-002.
    L_FIELDCAT-COL_POS = 2.
    L_FIELDCAT-OUTPUTLEN = 10.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    * Message
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'MESG'.
    L_FIELDCAT-SELTEXT_M = TEXT-003.
    L_FIELDCAT-COL_POS = 3.
    L_FIELDCAT-OUTPUTLEN = 80.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    ENDFORM. " FIELDCAT_POPULATION
    *& Form ALV_DISPLAY
    * text
    * --> p1 text
    * <-- p2 text
    FORM ALV_DISPLAY.
    * Assign Report ID
    CALL_BACK_PRG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = CALL_BACK_PRG
    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    IT_FIELDCAT = G_T_FIELDCAT
    TABLES
    T_OUTTAB = G_T_FINAL[]
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " ALV_DISPLAY
    *& Form USER_COMMAND
    * text
    * --> p1 text
    * <-- p2 text
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    DATA : L_DATE1 TYPE SY-DATUM,
    L_DATE2 TYPE SY-DATUM,
    L_YEAR(4),
    L_MONTH(2),
    L_DATE(2).
    CLEAR : L_DATE,L_DATE1,L_DATE2,L_YEAR,L_MONTH.
    L_DATE1 = SY-DATUM.
    L_YEAR = L_DATE1(4).
    L_MONTH = L_DATE1+4(2).
    L_DATE = L_DATE1+6(2).
    CONCATENATE L_DATE L_MONTH L_YEAR INTO L_DATE2 .
    CASE R_UCOMM.
    WHEN '&IC1'. "doubleclick
    CHECK RS_SELFIELD-FIELDNAME = 'EBELN'.
    READ TABLE G_T_FINAL INDEX RS_SELFIELD-TABINDEX.
    IF SY-SUBRC = 0.
    READ TABLE G_T_TEMP WITH KEY LOGNUM = G_T_FINAL-LOGNUM.
    IF SY-SUBRC = 0.
    MESSAGE I899(KB) WITH TEXT-004.
    ELSE.
    SET PARAMETER ID 'BES' FIELD G_T_FINAL-EBELN.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'COHEADER-SEND_REC_REL'
    '05SAP'.
    PERFORM BDC_FIELD USING 'RK23F-STATUS'
    'S'.
    PERFORM BDC_FIELD USING 'COHEADER-BLDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-BUDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-PERIO'
    L_MONTH.
    PERFORM BDC_FIELD USING 'RK23F-KSTAR'
    G_T_FINAL-KSTAR.
    PERFORM BDC_FIELD USING 'RK23F-WTGBTR'
    G_T_FINAL-AMOUNT.
    PERFORM BDC_FIELD USING 'RK23F-WAERS'
    G_T_FINAL-WAERS.
    PERFORM BDC_FIELD USING 'RK23F-SPSPNR'
    G_T_FINAL-POSID_OLD.
    PERFORM BDC_FIELD USING 'BDC_CURSOR'
    'RK23F-EPSPNR'.
    PERFORM BDC_FIELD USING 'RK23F-EPSPNR'
    G_T_FINAL-POSID_NEW.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'BDC_OKCODE'
    '=BACK'.
    PERFORM BDC_FIELD USING 'COHEADER-SEND_REC_REL'
    '05SAP'.
    PERFORM BDC_FIELD USING 'RK23F-STATUS'
    'S'.
    PERFORM BDC_FIELD USING 'COHEADER-BLDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-BUDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-PERIO'
    L_MONTH.
    PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0100'.
    PERFORM BDC_FIELD USING 'BDC_OKCODE'
    '=NO'.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'BDC_CURSOR'
    'RK23F-KSTAR'.
    PERFORM BDC_FIELD USING 'RK23F-WAERS'
    G_T_FINAL-WAERS.
    *perform bdc_dynpro using 'SAPLK23F1' '1200'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'COHEADER-SEND_REC_REL'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=PVAR'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'L'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLK23F1' '1200'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-STATUS'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=LISI'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_OKCODE'
    * '/00'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_field using 'RK23F-KSTAR'
    * g_t_final-kstar.
    *perform bdc_field using 'RK23F-WTGBTR'
    * g_t_final-amount.
    *perform bdc_field using 'RK23F-WAERS'
    * g_t_final-waers.
    *perform bdc_field using 'RK23F-SPSPNR'
    * g_t_final-posid_old.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-EPSPNR'.
    *perform bdc_field using 'RK23F-EPSPNR'
    * g_t_final-posid_new.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=BACK'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLSPO1' '0100'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=NO'.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-KSTAR'.
    *perform bdc_field using 'RK23F-WAERS'
    * g_t_final-waers.
    CALL TRANSACTION 'KB11N' USING G_T_BDC MODE 'A' MESSAGES
    INTO G_T_MESSAGE.
    IF NOT G_T_MESSAGE[] IS INITIAL.
    READ TABLE G_T_MESSAGE WITH KEY MSGTYP = 'S'.
    IF SY-SUBRC = 0.
    DELETE FROM BALHDR WHERE LOGNUMBER = G_T_FINAL-LOGNUM AND
    OBJECT = G_T_FINAL-OBJECT AND
    SUBOBJECT = G_T_FINAL-SUBOBJECT.
    COMMIT WORK.
    G_T_TEMP = G_T_FINAL.
    APPEND G_T_TEMP.
    ENDIF.
    ENDIF.
    *refresh g_t_bdc.
    CLEAR G_T_BDC.
    REFRESH G_T_BDC.
    ENDIF.
    ENDIF.
    ENDCASE.
    ENDFORM. " USER_COMMAND
    *& Form bdc_dynpro
    * text
    * -->P_0510 text
    * -->P_0511 text
    FORM BDC_DYNPRO USING PROGRAM
    DYNPRO.
    CLEAR G_T_BDC.
    G_T_BDC-PROGRAM = PROGRAM.
    G_T_BDC-DYNPRO = DYNPRO.
    G_T_BDC-DYNBEGIN = 'X'.
    APPEND G_T_BDC.
    ENDFORM. " bdc_dynpro
    *& Form bdc_field
    * text
    * -->P_0555 text
    * -->P_G_T_FINAL_WAERS text
    FORM BDC_FIELD USING FNAM
    FVAL.
    IF FVAL <> SPACE.
    CLEAR G_T_BDC.
    G_T_BDC-FNAM = FNAM.
    G_T_BDC-FVAL = FVAL.
    APPEND G_T_BDC.
    ENDIF.
    ENDFORM. " bdc_field
    Jogdand M B

  • How to use INNER JOIN in such case

    when i program as below[CASE1]. the code is able to active.
    CASE1:
    ==========================
    DATA: WK_BUKRS LIKE T001-BUKRS,
          WK_BUTXT LIKE T001-BUTXT,
          WK_TABLE(4) TYPE C VALUE 'T001'.
    START-OF-SELECTION.
      WK_BUKRS = 'DECN'.
      PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
                     CHANGING WK_BUTXT.
      WRITE: WK_BUTXT.
      FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
                           I_TABLE
                  CHANGING O_BUTXT LIKE T001-BUTXT.
        SELECT SINGLE BUTXT
                 INTO O_BUTXT
                 FROM (I_TABLE)
                WHERE BUKRS = I_BUKRS.
      ENDFORM.                   
    ===========================
    but when I need to INNER JOIN another table [CASE2]
    CASE2:
    =======================
    DATA: WK_BUKRS LIKE T001-BUKRS,
          WK_BUTXT LIKE T001-BUTXT,
          WK_TABLE(4) TYPE C VALUE 'T001'.
    START-OF-SELECTION.
      WK_BUKRS = 'DECN'.
      PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
                     CHANGING WK_BUTXT.
      WRITE: WK_BUTXT.
      FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
                           I_TABLE
                    CHANGING O_BUTXT LIKE T001-BUTXT.
        SELECT SINGLE BUTXT
                 INTO O_BUTXT
                 FROM (I_TABLE) AS G INNER JOIN BKPF AS H
                   ON GBUKRS = HBUKRS
                WHERE G~BUKRS = I_BUKRS.
      ENDFORM.          
    =================================
    Syntax error:
    Wrong expression "INNER" in FROM clause. WHERE condition.
    Can anybody help me to solve the problem.
    My requirement is to use INNER JOIN with variable table

    hi slam,
    chk this sample code.
    hi,
    table emp
    empno name
    a sasi
    b xxx
    c yyy
    table sal
    empno salary
    a 1000
    b 2000
    Inner join
    select eempno ename
    s~sal
    into table int_table
    from emp as e
    inner join sal as s
    on
    eempno = sempno.
    if you made inner join between table a and b by emp no
    the selection retrives only if the condition satisfy the output will be
    a sasi 1000
    b xxx 2000
    rgds
    anver
    if hlped mark points
    Message was edited by: Anversha s

  • Select querry using inner join

    Hi Friends,
    I need to fetch data from two tables, I used inner join but I am not able to fetch the data in some fields can any one tell me what is wrong in this select querry.
    SELECT but000~partner
             but000~name_org1
             but000~name_first
             but000~name_last
             but000~bpext
          FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart
        INTO table lt_but000
        WHERE but000~partner IN so_part
        AND dfkkop~faedn IN so_faedn.
    Thanx in advance,
    Parvez

    hi Lutin,
    SELECT but000~partner
    but000~name_org1
    but000~name_first
    but000~name_last
    but000~bpext
    FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart  <------check this condition,it has to *satisfy  both table                                                                        
    INTO table lt_but000
    WHERE but000~partner IN so_part
    AND dfkkop~faedn IN so_faedn.
    Regards,
    siva
    Message was edited by:
            SivaKumar

  • Trying to convert SELECT query to Update query with INNER JOINS

    Assalam O Alaikum!
    I've tried to convert this query of mine but failed.
    I wish to use it for update datasource in data GridView. I'm fetching data with it but converting it to update is not helping giving multiple errors.
    I tried to share the pic but they don't let me do so. Its actually a gridView with check boxes. check the item and update it..
    Here is the query. Please help me with that.
    <pre>
    SELECT [rightsId], [saveRights], [updateRights],
    [viewRights], [deleteRights], [printRights],
    [processRights], [verifyRights], [unProcessRights],
    [unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
    FROM [tblRights] inner join tblMenu ON
    tblMenu.menuId=tblRights.menuId INNER JOIN
    tblGroup ON tblGroup.groupId=tblRights.rightsId
    </pre>

    code is fine the above query works fine with the fetching(select) but when I try to write it with update it doesn't. Here is the asp code. I'm doing nothing with c# or vb.
      <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                DataSourceID="ratGrid" AutoGenerateColumns="False"
                CssClass="GridViewStyle" Width="100%" AllowSorting="True" AutoGenerateEditButton="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
                <Columns>
                    <asp:BoundField DataField="rightsId" HeaderText="rightsId" ItemStyle-Width="75px" SortExpression="rightsId" Visible="False">
                    <ItemStyle Width="75px" />
                    </asp:BoundField>
                    <asp:CheckBoxField DataField="saveRights" HeaderText="Save" SortExpression="saveRights" />
                    <asp:CheckBoxField DataField="updateRights" HeaderText="Update" SortExpression="updateRights" />
                    <asp:CheckBoxField DataField="viewRights" HeaderText="View" SortExpression="viewRights" />
                    <asp:CheckBoxField DataField="deleteRights" HeaderText="Delete" SortExpression="deleteRights" />
                    <asp:CheckBoxField DataField="printRights" HeaderText="Print" SortExpression="printRights" />
                    <asp:CheckBoxField DataField="processRights" HeaderText="Process" SortExpression="processRights" />
                    <asp:CheckBoxField DataField="verifyRights" HeaderText="Verify" SortExpression="verifyRights" />
                    <asp:CheckBoxField DataField="unProcessRights" HeaderText="UnProcess" SortExpression="unProcessRights" />
                    <asp:CheckBoxField DataField="unVerifyRights" HeaderText="UnVerify" SortExpression="unVerifyRights" />
                    <asp:BoundField DataField="groupId" HeaderText="groupId" ReadOnly="True" SortExpression="groupId" Visible="False" />
                    <asp:BoundField DataField="menuid" HeaderText="menuid" SortExpression="menuid" ReadOnly="True" Visible="False" />
                </Columns>
                <RowStyle CssClass="RowStyle" BackColor="#FFF7E7" ForeColor="#8C4510" />
                <PagerStyle CssClass="PagerStyle" ForeColor="#8C4510" HorizontalAlign="Center" />
                <SelectedRowStyle CssClass="SelectedRowStyle" BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                <HeaderStyle CssClass="HeaderStyle" BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle CssClass="AltRowStyle" />
                <SortedAscendingCellStyle BackColor="#FFF1D4" />
                <SortedAscendingHeaderStyle BackColor="#B95C30" />
                <SortedDescendingCellStyle BackColor="#F1E5CE" />
                <SortedDescendingHeaderStyle BackColor="#93451F" />
            </asp:GridView>
            <asp:SqlDataSource ID="ratGrid"
                 runat="server"
                ConnectionString="<%$ ConnectionStrings:Conn_Str %>"
                SelectCommand="SELECT [rightsId], [saveRights], [updateRights],
    [viewRights], [deleteRights], [printRights],
    [processRights], [verifyRights], [unProcessRights],
    [unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
    FROM [tblRights] inner join tblMenu ON
    tblMenu.menuId=tblRights.menuId INNER JOIN
    tblGroup ON tblGroup.groupId=tblRights.rightsId"
               FilterExpression="menuId like '{0}%' and [groupId] like '{1}%'" >
                            <FilterParameters>
                <asp:ControlParameter ControlID="ddlmenu" Name="menu"
                        PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="ddlgroup" Name="Country"
                        PropertyName="SelectedValue" Type="String" />
                </FilterParameters>
            </asp:SqlDataSource>
    Your table needs key(s) and you need to assign the key as DataKeys property for the GridView to make your UpDate and Delete work without coding.

  • How to re-write this big SELECT Query with INNER JOINs?

    Hi Experts
    I have a performance killer SELECT query with an inner join of 3 tables u2013 VBAP, VBAK and VBEP together, which populates records to an internal table INT_COLL_ORD. Based on these records selected, in another SELECT query, records are fetched from VBUK table to the internal table INT_VBUK.
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV D~AUART E~ETTYP E~EDATU
    INTO TABLE INT_TAB_RES
    FROM VBAP AS A INNER JOIN VBAK AS D
    ON D~VBELN EQ A~VBELN AND D~MANDT EQ A~MANDT
    INNER JOIN VBEP AS E
    ON E~VBELN EQ A~VBELN AND E~POSNR EQ A~POSNR AND E~MANDT EQ A~MANDT
    WHERE  A~VBELN IN s_VBELN AND
           D~auart in s_auart AND
           D~vkorg in s_vkorg AND
           D~vbtyp eq 'C'     AND
           ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
           OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
           A~ABGRU EQ SPACE AND
           A~MTVFP IN R_MTVFP AND
           A~PRCTR IN R_PRCT AND
           E~ETENR EQ '1'.
    SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
    DELETE ADJACENT DUPLICATES FROM INT_TAB_RES COMPARING VBELN POSNR.
    CHECK NOT INT_TAB_RES [] IS INITIAL.
    SELECT VBELN UVALL CMGST INTO TABLE INT_VBUK
    FROM VBUK FOR ALL ENTRIES IN INT_TAB_RES
    WHERE VBELN = INT_TAB_RES-VBELN AND UVALL NE 'A'.
    Now, the requirement is:
    I want to split this query. Like, first join VBAK and VBUK first. With this selection, go to the inner join of VBAP and VBEP (on key VBELN) to get the results. How can I re-write this Query?
    Please help.
    Thx n Rgds

    Hi Nagraj
    As of your suggestion, I have re-written the query as below:
    * Declarations
    TYPES: BEGIN OF TYP_COLL_ORD,
            VBELN  LIKE VBAK-VBELN,
            POSNR  LIKE VBUP-POSNR,
            MATNR  LIKE VBAP-MATNR,
            KWMENG LIKE VBAP-KWMENG,
            KBMENG LIKE VBAP-KBMENG,
            ERDAT  LIKE VBAK-ERDAT,
            ERZET  LIKE VBAK-ERZET,
            PSTYV  LIKE VBAP-PSTYV,
            AUART  LIKE VBAK-AUART, u201Calready exists in type
            ETTYP  LIKE VBEP-ETTYP,
            EDATU  LIKE VBEP-EDATU.
    TYPES: END OF TYP_COLL_ORD.
    DATA: INT_COLL_ORD TYPE TABLE OF TYP_COLL_ORD WITH HEADER LINE.
    TYPES: BEGIN OF TYP_VBUK,
            AUART  LIKE VBAK-AUART, u201Chave added this field
            VBELN  LIKE VBUK-VBELN,
            UVALL  LIKE VBUK-UVALL,
            CMGST  LIKE VBUK-CMGST.
    TYPES: END OF TYP_VBUK.
    DATA: INT_VBUK TYPE TABLE OF TYP_VBUK WITH HEADER LINE.
    *QUERY#1 u2013 for VBAK & VBUK Join
    SELECT A~AUART B~VBELN B~UVALL B~CMGST
    INTO TABLE INT_VBUK
    FROM VBAK AS A INNER JOIN VBUK AS B
    ON A~VBELN EQ B~VBELN
    WHERE A~VBELN IN s_VBELN AND
    A~auart in s_auart AND
    A~vkorg in s_vkorg AND
    A~vbtyp eq 'C' AND
    B~UVALL NE 'A'.
    IF NOT INT_VBUK[] IS INITIAL.
    SORT INT_VBUK BY VBELN.
    DELETE ADJACENT DUPLICATES FROM INT_VBUK COMPARING VBELN.
    *QUERY#2 u2013 for VBAP & VBEP Join
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV B~ETTYP B~EDATU
    INTO TABLE INT_COLL_ORD
    FROM VBAP AS A INNER JOIN VBEP AS B
    ON B~VBELN EQ A~VBELN AND B~POSNR EQ A~POSNR AND B~MANDT EQ A~MANDT
    FOR ALL ENTRIES IN INT_VBUK
    WHERE A~VBELN = INT_VBUK-VBELN AND
    ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
    OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
    A~ABGRU EQ SPACE AND
    A~MTVFP IN R_MTVFP AND
    A~PRCTR IN R_PRCT AND
    B~ETENR EQ '1'.
    ENDIF.
      SORT INT_COLL_ORD BY  VBELN POSNR ETTYP.
      DELETE ADJACENT DUPLICATES FROM INT_COLL_ORD
        COMPARING VBELN POSNR.
      CHECK NOT INT_COLL_ORD[] IS INITIAL.
      LOOP AT INT_COLL_ORD.
        CLEAR: L_MTART,L_ATPPR,L_ETTYP.
        IF L_PREVIOUS_ETTYP NE INT_COLL_ORD-ETTYP OR
          L_PREVIOUS_AUART NE INT_COLL_ORD-AUART.
          READ TABLE INT_OVRCTL WITH KEY AUART = INT_COLL_ORD-AUART ETTYP = INT_COLL_ORD-ETTYP.
          CHECK SY-SUBRC NE 0.
    Now, the issue is:
    Please note that declaration for INT_COLL_ORD has a field AUART, which is used in further parts of program (see the statement just above)
    But, since neither VBAP nor VBEP contains AUART field, it cannot be fetched through the QUERY#2. So this value is not populated into INT_COLL_ORD through SELECT Query.
    Since this field is used in later part of program & that the internal table has no value for this field, it dumps!!
    How to include this value into the INT_COLL_ORD?
    Plz suggest....

  • How to use Inner join of table as Source in Merge statement in SQL

    Hi All,
        I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
    Following is the query 
    Merge Into EmpDept Target
    Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
    On Source.EmpId=Target.EmpId
    when not matched then
    Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
    values
    (Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
    When matched then 
    Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId      = Source.EmailId     ,Target.Ename       = Source.Ename      ,Target.ManagerId = Source.ManagerId , Target.Salary        = Source.Salary       ,Target.DeptId      = Source.DeptId      ,Target.DeptName = Source.DeptName ,Target.Location    = Source.Location;
    This is error while executing the above merge statement 
    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
    Please suggest me where i am wrong.. 
    Niraj Sevalkar

    MERGE INTO EmpDept Target
    Using (SELECT E.Address,
    e.Design,
    e.EmailId,
    e.EmpId,
    e.Ename,
    e.ManagerId,
    e.Salary,
    D.DeptId,
    D.DeptName,
    D.Location
    FROM Employee E
    INNER JOIN Dept D
    ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
    ON Source.EmpId = Target.EmpId
    WHEN NOT matched THEN
    INSERT (Address,
    Design,
    EmailId,
    EmpId,
    Ename,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    VALUES (Address,
    Design,
    EmailId,
    EmpId,
    EName,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    WHEN matched THEN
    UPDATE SET Address = Source.Address,
    Design = Source.Design,
    EmailId = Source.EmailId,
    Ename = Source.Ename,
    ManagerId = Source.ManagerId,
    Salary = Source.Salary,
    DeptId = Source.DeptId,
    DeptName = Source.DeptName,
    Location = Source.Location;

  • Select Query with Inner Join

    Dear Experts,
    I have writen a inner join code with MKPF and MSEG which taking too much time, while I have used index.
    Indexes are:
    MSEG
    MATNR
    WERKS
    LGORT
    BWART
    SOBKZ
    MKPF
    BUDAT
    MBLNR
    My Select Query is :
      SELECT B~MATNR
                   B~MAT_KDAUF
                   B~MAT_KDPOS
                   B~BWART
                   B~MENGE
                   B~MEINS
                   B~AUFNR
        INTO TABLE IT_MSEG
        FROM MKPF AS A
          INNER JOIN MSEG AS B
             ON AMBLNR EQ BMBLNR
            AND AMJAHR EQ BMJAHR
        WHERE A~BUDAT IN BUDAT
          AND B~MATNR IN MATNR
          AND B~WERKS IN WERKS
          AND B~LGORT IN LGORT
          AND B~BWART IN BWART.

    hi,
    you can use  for all entries  it will work faster then joins
    About it:*
    FOR ALL ENTRIES WHERE
    Syntax
    ... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
    Effect
    If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
    The internal table itab must have a structured line type and the component comp must be compatible with the column col.
    The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
    The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
    Notes
    In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
    The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
    Example
    Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
    PARAMETERS p_city TYPE spfli-cityfrom.
    TYPES: BEGIN OF entry_tab_type,
             carrid TYPE spfli-carrid,
             connid TYPE spfli-connid,
           END OF entry_tab_type.
    DATA: entry_tab   TYPE TABLE OF entry_tab_type,
          sflight_tab TYPE SORTED TABLE OF sflight
                           WITH UNIQUE KEY carrid connid fldate.
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF TABLE entry_tab
           WHERE cityfrom = p_city.
    SELECT carrid connid fldate
           FROM sflight
           INTO CORRESPONDING FIELDS OF TABLE sflight_tab
           FOR ALL ENTRIES IN entry_tab
           WHERE carrid = entry_tab-carrid AND
                 connid = entry_tab-connid.
    hope it will help you
    Rahul sharma
    Edited by: RAHUL SHARMA on Sep 11, 2008 8:10 AM

  • Query contain inner join to external DB

    Hi every body,
    I have created a new sql query that contain inner join to external db of the production software. The query also uses parameters for filter data by date .
    I succeeded to create a qurey that will work including inner join to the external DB and parameters,
    Here is the query:
    SELECT T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity, T1.TotalSumSy, T1.LineTotal, T0.Canceled, T2.Family
       FROM  [XXX].dbo.AllItems T2
         RIGHT OUTER JOIN INV1 T1 ON T1.ItemCode=          T2.ItemPN collate SQL_Latin1_General_CP1_CI_AS
         INNER JOIN OINV T0 ON T1.DocEntry = T0.DocEntry
         INNER JOIN OITM T3 ON T1.ItemCode = T3.ItemCode
         INNER JOIN OITB T4 ON T3.ItmsGrpCod = T4.ItmsGrpCod
         INNER JOIN OCRD T5 ON T0.CardCode = T5.CardCode
         INNER JOIN OACT T6 ON T1.AcctCode = T6.AcctCode
    Where T0.DocDate BETWEEN [%0] AND [%1]
    but when I add a union statement the query does not work again.
    If I remove the parameters every thing is working fine.
    what is the problem with my query?
    Thank you all very much.

    SBO does not manage correctly variables in complicated query.  There is a note about it:
    Note 730960 - SAP Business One does not identify variables in long queries
    https://websmp130.sap-ag.de/sap/bc/bsp/spn/sapnotes/index2.htm?numm=730960
    This note describe the method to get the parameters in variables and their usage.

  • Relationship between tables while using inner joins.

    Hi,
    I had a few clarifications on "inner joins", and as i was going through the forum, i came across two points,
    1. In one of the threads it said " inner joins is applicable for tables that have a parent child relationship.
    2. In another thread it said " inner join is established from master table (the table on the left) to the transcation table (the table on the right)".
    I have two clarifications based on the above points.
    1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
    2.  Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
    Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>.
    Edited by: Narayananchandran on Dec 27, 2010 12:31 PM

    have two clarifications based on the above points.
    1. Is it necessary that the tables on which im performing an inner join should have a parent-child/children relationship or is it enough that the tables just have a common field.
    2. Also is it necessary that the master table should come first, (or can i use any child table from where i can fetch the records when there is a mater table in my report) as shown below.
    Eg: select * <fields> from <master table> inner join <table> on <field> into <itab>
    1) NO
                      2) NO

  • Convert SSRS dropdown MDX query to INNER JOIN w/ NONEMPTY? Having hard time with this.

    I'm having an incredibly hard time with this, mostly because I'm very new with MDX.
    I created a simple report (with AdventureWorksDW) whose datasource is an SSAS cube. I select a datekey from the dropdown menu, and the report displays [Measures].[Order Quantity] for that day.
    The problem is that the dropdown displays every single value from the dimdate dimension. DimDate goes from 20050101 to 20201231, so the dropdown is very long.
    How can I alter the SSRS-generated MDX so that it does an INNER JOIN with Fact table and only the dates shown in the dropdown are the ones where there's data in the Fact table?
    Currently, the fact table only has 2 days of data (20141015, 20141016), which means that the dropdown should only display those two dates. I'm including the generated code MDX that populates the dropdown menu:
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS , [Dim Date].[Date Key].ALLMEMBERS ON ROWS
    FROM [Adventure Works cube]
    Any help is appreciated.
    VM

    Hi vmhatup,
    you can get rid of blank data using nonempty function and get rid of negative values using filter function nonempty should be inside of filter so it applies first, otherwise it is too slow.
    Your statement could look like this
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS
    , filter(
    nonempty([Dim Date].[Date Key].[Date Key],measures.measureName)
    ,measure.measurename >0
    ON ROWS
    FROM [Adventure Works cube]
    Jiri Neoral

  • Query on inner join

    Hello experts,
    i 'd like to join the tables BKPF and BSEG using the joins concept. let me know the statement for this so that i get the output as desired. USING selection screen concept as well.
    BKPF-BELNR,
    BKPF-BUKRS
    BKPF-GJAHR ( FISCAL YEAR)
    BSEG-WRBTR (VOUCHAR AMOUNT)
    BSEG-WRBTR( CREDIT )
    BSEG-WRBTR( DEBIT)
    Regards,
    CHK

    I tried using the Same, not working.
    ROB: any suggestion.
    Code:
    select *
    INTO TABLE BSEGitab
    FROM bkpf AS a
    INNER JOIN bseg AS b
    ON abelnr= bbelnr
    WHERE a~LIFNR IN Vendor
    and b~BUDAT LE Ikeydate.

  • Syntax errors in update query with inner joins and sub query.

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....
    sp_CFQ_Coord_Corrections is a table and not a stored procedure.
    are these both tables "sp_CFQ_Coord_Corrections" and "CFQ_Coord_Corrections" different ??

Maybe you are looking for