Order By Parameter UNION Issue!!

Hi All,
i have a query in which i have to order by a parameter.
but my problem is order by works only for non-union query if i add union to the query it gives error.
please see following..
SQL> SELECT   H.BOL_NUMBER BOL_NUMBER,
  2           H.PICKUP_NUMBER,
  3     to_char(H.PICKUP_DATE,'DD-MON-YYYY') PICKUP_DATE,
  4           RAC.CUSTOMER_NAME CUSTOMER_NAME,
  5           L.SALES_ORDER,
  6    to_char(MAX(PH.DATE_CONFIRMED),'DD-MON-YYYY HH24:MI:SS') DATE_CONFIRMED
  7  FROM     APPS.SO_PICKING_HEADERS_ALL PH,
  8    SMCOE.SMCOE_BOL_HEADERS H,
  9           SMCOE.SMCOE_BOL_LINES L,
10           SO_HEADERS_ALL SHA,
11           SO_ORDER_TYPES_ALL SOTA,
12           APPS.RA_CUSTOMERS RAC,
13    APPS.SO_PICKING_LINES_ALL PL,
14    APPS.SO_PICKING_LINE_DETAILS PLD
15  WHERE    H.BOL_HEADER_ID = L.BOL_HEADER_ID
16           AND L.SO_HEADER_ID = SHA.HEADER_ID
17           AND SHA.ORDER_TYPE_ID = SOTA.ORDER_TYPE_ID
18           AND L.CUSTOMER_ID = RAC.CUSTOMER_ID
19           AND H.PICKUP_DATE >= TO_DATE('3-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
20           AND H.PICKUP_DATE < TO_DATE('4-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
21           AND DECODE(NULL,NULL,'X',
22                                 RAC.CUSTOMER_NAME) = DECODE(NULL,NULL,'X',
23                                                                        NULL)
24           AND DECODE(634307,NULL,1,
25                            H.BOL_NUMBER) = DECODE(634307,NULL,1,
26                                                         634307)
27    AND decode('Only SO','Only SO','Z',RAC.CUSTOMER_NAME)=decode('Only SO','Only SO','Z','XXX')
28    AND PH.DATE_CONFIRMED IS NOT NULL
29    AND PH.PICKING_HEADER_ID=PL.PICKING_HEADER_ID
30    AND PL.PICKING_LINE_ID=PLD.PICKING_LINE_ID
31    AND PLD.PICKING_LINE_DETAIL_ID=L.PICKING_LINE_DETAIL_ID
32    AND NOT EXISTS (SELECT 1
33         FROM SO_PICKING_LINE_DETAILS SPLD,WSH_DELIVERIES WD
34         WHERE SPLD.DELIVERY_ID=WD.DELIVERY_ID
35         AND SPLD.PICKING_LINE_DETAIL_ID =L.PICKING_LINE_DETAIL_ID
36         AND WD.STATUS_CODE='OP'
37        )
38   GROUP BY H.BOL_NUMBER ,
39           H.PICKUP_NUMBER,
40           H.PICKUP_DATE ,
41           RAC.CUSTOMER_NAME ,
42           L.SALES_ORDER,
43           L.LINE_NUMBER,
44           L.GROSS_WEIGHT,
45           L.NET_WEIGHT,
46           L.TARE_WEIGHT
47  ORDER BY decode('CUSTOMER','DATE',PICKUP_DATE,'CUSTOMER',CUSTOMER_NAME,'PN',PICKUP_NUMBER,SALES_ORDER);
BOL_NUMBER PICKUP_N PICKUP_DATE CUSTOMER_NAME                                                      
SALES_ORDER                                                                                        
DATE_CONFIRMED                                                                                     
    634307 SC22862  03-NOV-2006 A M CASTLE & CO                                                    
300014511                                                                                          
03-NOV-2006 19:05:01                                                                               
    634307 SC22862  03-NOV-2006 A M CASTLE & CO                                                    
300014542                                                                                          
03-NOV-2006 19:04:55                                                                               
    634307 SC22862  03-NOV-2006 A M CASTLE & CO                                                    
300014599                                                                                          
03-NOV-2006 19:04:56                                                                               
    634307 SC22862  03-NOV-2006 A M CASTLE & CO                                                    
300014637                                                                                          
03-NOV-2006 19:05:04                                                                               
    634307 SC22862  03-NOV-2006 CORROSION MATERIALS INC                                            
14 rows selected.
SQL> ed
Wrote file afiedt.buf
line 72 truncated.
  1  SELECT   H.BOL_NUMBER BOL_NUMBER,
  2           H.PICKUP_NUMBER,
  3             to_char(H.PICKUP_DATE,'DD-MON-YYYY') PICKUP_DATE,
  4           RAC.CUSTOMER_NAME CUSTOMER_NAME,
  5           L.SALES_ORDER,
  6              ' ' DATE_CONFIRMED
  7  FROM     SMCOE.SMCOE_BOL_HEADERS H,
  8           SMCOE.SMCOE_BOL_LINES L,
  9           APPS.RA_CUSTOMERS RAC
10  WHERE    H.BOL_HEADER_ID = L.BOL_HEADER_ID
11           AND L.CUSTOMER_ID = RAC.CUSTOMER_ID
12           AND H.PICKUP_DATE >= TO_DATE('3-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
13           AND H.PICKUP_DATE < TO_DATE('4-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
14           AND DECODE(NULL,NULL,'X',
15                                 RAC.CUSTOMER_NAME) = DECODE(NULL,NULL,'X',
16                                                                        NULL)
17           AND DECODE(NULL,NULL,1,
18                            H.BOL_NUMBER) = DECODE(NULL,NULL,1,
19                                                        NULL)
20           AND SALES_ORDER NOT LIKE '4%'
21           AND SALES_ORDER NOT LIKE 'PO%'
22           AND SALES_ORDER <> '1'
23           AND L.CUSTOMER_NAME NOT LIKE 'REC%'
24        AND decode('Only SO','Product','Y',RAC.CUSTOMER_NAME)=decode('Only SO','Product','Y','XXX')
25  UNION
26  SELECT   H.BOL_NUMBER BOL_NUMBER,
27           H.PICKUP_NUMBER,
28             to_char(H.PICKUP_DATE,'DD-MON-YYYY') PICKUP_DATE,
29           RAC.CUSTOMER_NAME CUSTOMER_NAME,
30           L.SALES_ORDER,
31        to_char(MAX(PH.DATE_CONFIRMED),'DD-MON-YYYY HH24:MI:SS') DATE_CONFIRMED
32  FROM     APPS.SO_PICKING_HEADERS_ALL PH,
33        SMCOE.SMCOE_BOL_HEADERS H,
34           SMCOE.SMCOE_BOL_LINES L,
35           SO_HEADERS_ALL SHA,
36           SO_ORDER_TYPES_ALL SOTA,
37           APPS.RA_CUSTOMERS RAC,
38        APPS.SO_PICKING_LINES_ALL PL,
39        APPS.SO_PICKING_LINE_DETAILS PLD
40  WHERE    H.BOL_HEADER_ID = L.BOL_HEADER_ID
41           AND L.SO_HEADER_ID = SHA.HEADER_ID
42           AND SHA.ORDER_TYPE_ID = SOTA.ORDER_TYPE_ID
43           AND L.CUSTOMER_ID = RAC.CUSTOMER_ID
44           AND H.PICKUP_DATE >= TO_DATE('3-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
45           AND H.PICKUP_DATE < TO_DATE('4-NOV-2006 00:00:00','DD-MON-YYYY HH24:MI:SS')
46           AND DECODE(NULL,NULL,'X',
47                                 RAC.CUSTOMER_NAME) = DECODE(NULL,NULL,'X',
48                                                                        NULL)
49           AND DECODE(634307,NULL,1,
50                            H.BOL_NUMBER) = DECODE(634307,NULL,1,
51                                                         634307)
52        AND decode('Only SO','Only SO','Z',RAC.CUSTOMER_NAME)=decode('Only SO','Only SO','Z','XXX')
53        AND PH.DATE_CONFIRMED IS NOT NULL
54        AND PH.PICKING_HEADER_ID=PL.PICKING_HEADER_ID
55        AND PL.PICKING_LINE_ID=PLD.PICKING_LINE_ID
56        AND PLD.PICKING_LINE_DETAIL_ID=L.PICKING_LINE_DETAIL_ID
57        AND NOT EXISTS (SELECT 1
58                 FROM SO_PICKING_LINE_DETAILS SPLD,WSH_DELIVERIES WD
59                 WHERE SPLD.DELIVERY_ID=WD.DELIVERY_ID
60                 AND SPLD.PICKING_LINE_DETAIL_ID =L.PICKING_LINE_DETAIL_ID     
61                 AND WD.STATUS_CODE='OP'
62                )
63       GROUP BY H.BOL_NUMBER ,
64           H.PICKUP_NUMBER,
65           H.PICKUP_DATE ,
66           RAC.CUSTOMER_NAME ,
67           L.SALES_ORDER,
68           L.LINE_NUMBER,
69           L.GROSS_WEIGHT,
70           L.NET_WEIGHT,
71           L.TARE_WEIGHT           
72* ORDER BY decode('CUSTOMER','DATE',PICKUP_DATE,'CUSTOMER',CUSTOMER_NAME,'PN',PICKUP_NUMBER,SALES_ORDER)
SQL> /
OERROR at line 72:
ORA-01785: ORDER BY item must be the number of a SELECT-list expression
SQL> spool off;

Maybe you could try this:
select ...
from
   select ...
   from ..
   UNION
   select ...
   from ...
order by ...                                                                                                                                                                                                                                                                                   

Similar Messages

  • Query In SP runs 10x slower than straight query - NOT Parameter Sniffing Issue

    Hi Everyone,
    I have a real mystery on my hands that appears to be a parameter sniffing issue with my SP but I think is not. I have tried every parameter sniffing workaround trick in the book ( local variables, option recompile, with recompile, optimize for variables,UNKNOWN,
    table hints, query hints, MAXDOP, etc.) I have dropped indexes/recreated indexes, updated statistics, etc. I have restored a copy of the DB to 2 different servers ( one with identical HW specs as the box having the issue, one totally different ) and the SP
    runs fine on those 2, no workarounds needed. Execution plans are identical on all boxes. When I run a profiler on the 2 different boxes however, I see that on the server having issues, the Reads are around 8087859 while the other server with identical HW,
    the reads are 10608. Not quite sure how to interpret those results or where to look for answers. When the sql server service is restarted on the server having issues and the sp is run, it runs fine for a time ( not sure how long ) and then goes back to its
    snail pace speed. Here is the profile trace:
    Here is the stored procedure. The only modifications I made were the local variables to eliminate the obvious parameter sniffing issues and I added the WITH NOLOCK hints:
    /****** Object:  StoredProcedure [dbo].[EC_EMP_APPR_SIGNATURE_SEL_TEST]    Script Date: 12/03/2014 08:06:01 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    /****** Object:  StoredProcedure [dbo].[EC_EMP_APPR_SIGNATURE_SEL_TEST]    Script Date: 12/02/2014 22:24:45 ******/
    ALTER PROCEDURE [dbo].[EC_EMP_APPR_SIGNATURE_SEL_TEST]
    @EMPLOYEE_ID varchar(9) ,
    @OVERRIDE_JOB_CODE varchar(8),
    @OVERRIDE_LOCATION_CODE varchar(8),
    @OVERRIDE_EST_CODE varchar(8),
    @OVERRIDE_EMP_GROUP_CODE varchar(8)
    AS
    set NOCOUNT ON
    declare
    @EMPLOYEE_ID_LOCAL varchar(9),
    @OVERRIDE_JOB_CODE_LOCAL varchar(8),
    @OVERRIDE_LOCATION_CODE_LOCAL varchar(8),
    @OVERRIDE_EST_CODE_LOCAL varchar(8),
    @OVERRIDE_EMP_GROUP_CODE_LOCAL varchar(8)
    set @EMPLOYEE_ID_LOCAL = @EMPLOYEE_ID
    set @OVERRIDE_JOB_CODE_LOCAL = @OVERRIDE_JOB_CODE
    set @OVERRIDE_LOCATION_CODE_LOCAL = @OVERRIDE_LOCATION_CODE
    set @OVERRIDE_EST_CODE_LOCAL = @OVERRIDE_EST_CODE
    set @OVERRIDE_EMP_GROUP_CODE_LOCAL = @OVERRIDE_EMP_GROUP_CODE
    select 3 as SIGNATURE_ID
    from EC_EMPLOYEE_POSITIONS p
    where p.EMPLOYEE_ID = @EMPLOYEE_ID_LOCAL
     and DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) between p.POSITION_START_DATE and ISNULL(p.POSITION_END_DATE, convert(datetime, '47121231', 112))
     and (dbo.lpad(isnull(p.job_code,''), 8, ' ') + dbo.lpad(isnull(p.location_code,''), 8, ' ') + dbo.lpad(isnull(p.ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(p.EMP_GROUP_CODE,''), 8, ' '))
     in
     (select (dbo.lpad(isnull(ep.REPORTING_JOB_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_LOCATION_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_EMP_GROUP_CODE,''),
    8, ' '))
      from EC_POSITIONS  ep
      where DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) between ep.POSITION_EFFECT_DATE
       and ISNULL(ep.POSITION_TERM_DATE, convert(datetime, '47121231', 112))
       and (dbo.lpad(isnull(ep.job_code,''), 8, ' ') + dbo.lpad(isnull(ep.location_code,''), 8, ' ') + dbo.lpad(isnull(ep.ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.EMP_GROUP_CODE,''), 8, ' '))
       = (dbo.lpad(isnull(@OVERRIDE_JOB_CODE_LOCAL,''), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_LOCATION_CODE_LOCAL,''), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_EST_CODE_LOCAL,'<N/A>'), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_EMP_GROUP_CODE_LOCAL,''),
    8, ' ')))
    union
    select 4 as SIGNATURE_ID
    from EC_EMPLOYEE_POSITIONS p
    where p.EMPLOYEE_ID = @EMPLOYEE_ID_LOCAL
     and DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) between p.POSITION_START_DATE and ISNULL(p.POSITION_END_DATE, convert(datetime, '47121231', 112))
     and (dbo.lpad(isnull(p.job_code,''), 8, ' ') + dbo.lpad(isnull(p.location_code,''), 8, ' ') + dbo.lpad(isnull(p.ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(p.EMP_GROUP_CODE,''), 8, ' '))
     in
     (select (dbo.lpad(isnull(ep.REPORTING_JOB_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_LOCATION_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_EMP_GROUP_CODE,''),
    8, ' '))
      from EC_POSITIONS  ep with (NOLOCK)
      where DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) between ep.POSITION_EFFECT_DATE
       and ISNULL(ep.POSITION_TERM_DATE, convert(datetime, '47121231', 112))
       and (dbo.lpad(isnull(ep.job_code,''), 8, ' ') + dbo.lpad(isnull(ep.location_code,''), 8, ' ') + dbo.lpad(isnull(ep.ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.EMP_GROUP_CODE,''), 8, ' '))
       in   
     (select (dbo.lpad(isnull(ep.REPORTING_JOB_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_LOCATION_CODE,''), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.REPORTING_EMP_GROUP_CODE,''),
    8, ' '))
      from EC_POSITIONS ep  with (NOLOCK)
      where DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) between ep.POSITION_EFFECT_DATE
       and ISNULL(ep.POSITION_TERM_DATE, convert(datetime, '47121231', 112))
       and (dbo.lpad(isnull(ep.job_code,''), 8, ' ') + dbo.lpad(isnull(ep.location_code,''), 8, ' ') + dbo.lpad(isnull(ep.ESTABLISHMENT_CODE,'<N/A>'), 8, ' ') + dbo.lpad(isnull(ep.EMP_GROUP_CODE,''), 8, ' '))
       = (dbo.lpad(isnull(@OVERRIDE_JOB_CODE_LOCAL,''), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_LOCATION_CODE_LOCAL,''), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_EST_CODE_LOCAL,'<N/A>'), 8, ' ') + dbo.lpad(isnull(@OVERRIDE_EMP_GROUP_CODE_lOCAL,''),
    8, ' '))))
    order by SIGNATURE_ID
    Any suggestions would be greatly appreciated by anyone. I have no more tricks left in my toolbox and am starting to think its either the hardware or the database engine itself that is at fault.
    Max

    fast server:
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
    SQL Server Execution Times:
    CPU time = 0 ms, elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'EC_POSITIONS'. Scan count 3, logical reads 10450, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'EC_EMPLOYEE_POSITIONS'. Scan count 2, logical reads 6, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    SQL Server Execution Times:
       CPU time = 3343 ms,  elapsed time = 3460 ms.
    SQL Server Execution Times:
       CPU time = 3343 ms,  elapsed time = 3460 ms.
    Slow server:
    SQL Server parse and compile time:
       CPU time = 0 ms, elapsed time = 0 ms.
    SQL Server Execution Times:
    CPU time = 0 ms, elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 0 ms.
    Table 'EC_POSITIONS'. Scan count 3, logical reads 10450, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'EC_EMPLOYEE_POSITIONS'. Scan count 2, logical reads 6, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    SQL Server Execution Times:
       CPU time = 37875 ms,  elapsed time = 38295 ms.
    SQL Server Execution Times:
       CPU time = 37875 ms,  elapsed time = 38295 ms.
    Big diff in server execution times....

  • Open order qty,Delivered qty,issued qty, and closing stock---Tables

    Gurus,
    I need to Prepare a report which will show open order qty,Delivered qty,issued qty, and closing stock.
    Please help me with table names where i can find .
    Regards
    venu gopal

    Hi,
    Try EKPO & EKBE tables..
    Thx
    Raju

  • Purchase to Order Scenario - Partial Confirmation Issue

    Hello Team,
    We are using Item Category with Purchase to Order Scenario. When the Sales Order is booked, Purchase Requisition is Created. Sales Order Line is linked to the Purchase Requision/Purchase Order.
    In this scenario, we are getting confirmation on Sales Order through PR/PO Initially.
    Order Quantity     Confirmed Quantity
    10                         10
    Once we receive partial confirmation on PO let us say 7 system only confirms partially Sales Order.
    Order Quantity     Confirmed Quantity
    10                         7
    Issue happens when our team does partial delivery to customer before receiving full confirmation from the Supplier. System blocks further update of confirmation on the line and it becomes impossible to make delivery to Customer for Partial Quantity.
    I can think of two options...
    1. Somehow when we receive Partial Cofnirmation, our Availibility Check should confirm 7 on Confirmation recieved from the Supplier and 3 from Delivery Date of Purchase Order. So this issue won't happen.
    2. System should somehow allow Partial Confirmation even after Partial Delivery is done to the Customer.
    Do let me know if you need any more details from my side.
    Kaushal

    Hi Kaushal,
    i assume that you have special stock indicator in your sales order.
    if you do not use confiramtion then all quantities are confirmed at schedule line level.
    if you use confirmation e.x. 7 of 10 pieces then you will have confirmer 7 quantities in your schedule line.
    if you create another confirmation in PO of 2 pieces and lets say different date you will see another schedule line in your sales order.
    do your system works like this?
    Is your third party scenario require a googds receipt for PO to move on to delivery?
    Regards.

  • Using ORDER BY in UNION clause in cursor

    Hi Everybody,
    I have one situation and i need your help guys. I have to use ORDER BY in UNION of two queries and return value in cursor.
    OPEN cursor FOR
    SELECT ID, DESC,SID, ITID, SID_DESC
    FROM (SELECT A.ID,
    A.DESC,
    B.SID,
    NULL AS ITID,
    B.SID_DESC
    FROM TABLEA A, TABLEB B
    WHERE A.ID = B.ID
    order by A.SORTORDER asc,B.SORTORDER)
    UNION
    SELECT ID, DESC, ,SID,ITID, ITID_DESCRIPTION,
    FROM (SELECT A.ID,
    A.DESC,
    NULL AS SID,
    C.ITID,
    C.ITID_DESC,
    FROM TABLEA A,
    TABLEC C
    WHERE A.ID = C.ID
    order by A.SORTORDER asc,C.SORTORDER)
    I SORT ORDER is column in all three tables. TABLEA has unique number for each record as sort order. TABLEB has sortorder as 1 for each id. If id is two times then its 1 and 2 for each id. TABLEC has sort order as TABLEB, 1 for each id and if id is two times then it is 1 and 2 and id id is three times, it is 1, 2, 3.
    I am not getting correct sorting as i cant use order by like this in UNION. Please let me know how i can handle this.
    Thank you in advance to everybody.
    I will really appreciate your comments and responses.

    Hi,
    You can use ORDER BY in a sub-query, but there's usually no point in doing so, because the super-query won't necessarily preserve that order. You need to make the columns that you want to ORDER BY available to the main query, so that they can be used there.
    Try this:
    SELECT      ID, DESC,SID, ITID, SID_DESC
    FROM      (
             SELECT    A1.ID,
                        A1.DESC,
                    B.SID,
                    NULL          AS ITID,
                    B.SID_DESC,
                    A1.SORTORDER     AS sortorder_1
                    B.SORTORDER     AS sortorder_2
             FROM      TABLEA     A1,
                        TABLEB     B
             WHERE     A1.ID = B.ID
        UNION
             SELECT    A2.ID,
                        A2.DESC,
                    NULL          AS SID,
                           C.ITID,
                    C.ITID_DESC,
                    A2.SORTORDER     AS sortorder_1
                    B.SORTORDER     AS sortorder_2
             FROM      TABLEA          A2,
                        TABLEC         C
             WHERE     A2.ID = C.ID
    order by  SORTORDER_1     ASC     -- ASC is the default, but it doesn't hurt to say it
           SORTORDER_2This assumes that tableb.sortorder and tablec.sortorder have the same, or at least similar, data types. If not, explicitly convert sortorder_1 in one branch of the UNION to the type of sortorder_2 in the other branch.
    Using the same alias to mean different things in the same query is just asking for trouble. I changed the table alias a (which was used in different places to mean two different things) to A1 and A2, each of which means only one thing.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Order by clause + Union

    Hi ,
    i want to use "union" to combine 2 query results and also i need to apply order by clause in both queries,how i can achieve this
    i.e
    i wrote query like
    select item_id from item_mst
    where item_id <5
    order by item_no
    union
    select item_id from item_mst
    where item_id <10
    order by item_no
    But it is giving ORA-00933 error.
    Please help me to over come this error.
    Thanks in advance

    You cannot have an ORDER BY clause on each part of the union - there is only one ORDER BY allowed and that applies to the result of the union.
    select item_id from item_mst
    where item_id <5
    union
    select item_id from item_mst
    where item_id <10
    order by item_idI'm assuming you meant 'order by item_ID', not item_NO, since there is no item_NO column in the query.

  • Defining sort order using parameter fields

    Post Author: vandersee
    CA Forum: General
    I've created a report, the contents of which is sorted depending on a parameter selected (method used is as described in the help topic entitled "Defining sort order using parameter fields".  Is it possible to vary the Sort Direction (ascending/descending) using parameters also, so that if I choose to sort by field A it will be ascending, but descending if I choose to sort by field B?

    Post Author: V361
    CA Forum: General
    You can create a Parameter {?Sort Order}  make it a string, and add items A to Z and Z to A and a formula and sort the group using the formula.
    Group Expert, select the group, select options, check use a formula as group sort order
    if {?Sort Order} = "A to Z" then crAscendingOrder else crDescendingOrder
    And your group will sort based on what is selected in the parameter.

  • Order update parameter

    Hi friends.
    What is order update parameter? Is it related with RSA3 delta extractiion.?
    What if RSA3 delta extraction is not giving records for Delta mode ,it only extracts for Full mode my case is of 2lis_04_pematnr,setup table is o.k,plz help  ?

    Hi Girish,
    What is your delta update method - direct delta or queued delta? If it is queued delta is it simply because you have not scheduled the collective run to move the data to the delta queue? To schedule a collective run you can click on 'Job Control' in the customizing cockpit against 04 content area.
    Regards,
    Ken

  • Using order by in Union ALL

    hi Following is my query and am unable to accomplish my order by statement in Union All . please help me in this.
    <code>
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    a.lot_id,
    b.comment_text "Comments"
    FROM clem_audit_trail b,lot a, users u
    WHERE a.lot_id = b.lot_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND a.lot_id in (select lot_id from request_lot where request_id = 51914)
    AND col_name IN
    ('Interim Release Date',
    'Final Disposition Date',
    'On Time Disposition',
    'Intended Use',
    'REJECTS_YN',
    '# of QARs',
    '# of Quality Events',
    '# of LIRs',
    '# of Change Controls',
    '# of Batch Records',
    '# of GMP Batch Records',
    'EXPLANATION',
    'QA Notes',
    'GDMS_LINK')
    AND UPPER (table_name) IN('LOT') order by b.last_update_date
    UNION ALL
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    r.request_id,
    b.comment_text "Comments"
    FROM clem b,request r, users u
    WHERE r.request_id = b.request_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND r.request_id = 51914
    AND UPPER (table_name) IN ('REQUEST') AND
    b.col_name IN ('Partial Release',
    'All QP Docs in GDMS',
    'Number of Batch Records',
    'Request',
    'QP Issues',
    'Snag Comments',
    'Responsible Group',
    'Reason Late',
    'Study Impact',
    'Other Details',
    'Request Status',
    'QP Link to GDMS'
    ) order by b.last_update_date
    </code>
    If i execute individually it works fine, if i use union all it throughs error for me.
    Any suggestion...

    Hi,
    In a set operation (such as UNION) table aliases (such as b.) only have meaning within the branch in which they are defined. The ORDER BY clause is not part of any 1 branch, so a table alias can't be used there.
    In most cases, you can use a column name (or alias) from the first branch, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  "Revision Date"
    ;and you can always order by column number, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  2
    ;In this case, however, there's an extra problem. You're transforming the DATE to a string in the SELECT clause. The string is all that's available in the ORDER BY clause, and the string '19-NOV-2012' comes after the string '01-JAN-2015', because the character '1' comes after '0'. Perhaps the simplest solution is to have your front end, and not the query, format the dates. In SQL*Plus, you can do this:
    ALTER SESSION  SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
    SELECT    b.audit_trail_id,
              b.last_update_date    AS "Revision Date",
    order by  2
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • VertexShader - Parameter / Matrix Issues

    I'm trying to implement a simple mask-shader for my 2D engine and I'm having multiple issues getting it to work.
    Basically the shader takes two images and two matrices and tries to map back the vertex position of the sprites vertex back to the local mask space position and then calculate the local uv-coordinates for the mask, but I'm stuck with some basic calculations here.
    Bug 1: Divisions in the material-vertex kernel don't work at all. That's why I have to put invertedMaskSize (which is 1.0 / 128.0) into the shader (but we already know that )
    Bug 2: interpolated vars have to be float4, float2 is not possible (That's a pretty old bug as well)
    I tried the following changes in the shader. The shader posted here, just tries to display the resulting uv-coordinates. No textures are used.
    Case 1:
    interpolatedMaskUV = float4((vertexPos.x + halfMaskSize.x) * invertedMaskSize.x, (vertexPoss.y + halfMaskSize.y) * invertedMaskSize.y, 0.0, 0.0);
    The output is this: http://dev.nulldesign.de/plain_uvcoords.png Just like you expect! Perfect, let's proceed.
    Case 2:
    Change the halfMaskSize and invertedMaskSize to float2 and set set the parameters as two vectors of length two of course in AS. The output: http://dev.nulldesign.de/float2_uvcoords.png
    Case 3:
    Masking Test, matrix multiplication. First calculating the world space position of the vertex:
    float4 worldSpacePos = float4(vertexPos.x, vertexPos.y, 0.0, 1.0) * objectToClipSpaceTransform;
    Then mapping it back to the local space of the mask:
    float4 localMaskSpacePos = worldSpacePos * maskObjectToClipSpaceTransform;
    And calculating the uv-coords:
    interpolatedMaskUV = float4((localMaskSpacePos.x + halfMaskSize.x) * invertedMaskSize.x, (localMaskSpacePos.y + halfMaskSize.y) * invertedMaskSize.y, 0.0, 0.0);
    For testing, I set the maskObjectToClipSpaceTransform to the inverse of the objectToClipSpaceTransform. In theory and on paper, this should work.
    But, I think, something gets out of order and maybe the maskObjectToClipSpaceTransform is screwed up in the shader, just like when I set the halfMaskSize and invertedMaskSize to float2. The result is this: http://dev.nulldesign.de/local_uvcoords.png and I have no idea how to fix this...
    <languageVersion : 1.0;>
    material kernel texture
    <
        namespace : "ND2D_Shader";
        vendor : "nulldesign";
        version : 1;
    >
        input vertex float2 uvCoord
        <
            id : "PB3D_UV";
        >;
        input vertex float2 vertexPos
        <
            id : "PB3D_POSITION";
        >;
        parameter float2 uvOffset;
        parameter float4x4 objectToClipSpaceTransform;
        parameter float4x4 maskObjectToClipSpaceTransform;
        // if set to float2, strange things happen
        parameter float4 halfMaskSize;
        parameter float4 invertedMaskSize;
        interpolated float4 interpolatedUV;
        interpolated float4 interpolatedMaskUV;
        void evaluateVertex()
            // not used in the current test ...
            interpolatedUV = float4(uvCoord.x + uvOffset.x, uvCoord.y + uvOffset.y, 0.0, 0.0);
            float4 worldSpacePos = float4(vertexPos.x, vertexPos.y, 0.0, 1.0) * objectToClipSpaceTransform;
            // doesn't work as expected
            float4 localMaskSpacePos = worldSpacePos * maskObjectToClipSpaceTransform;
            interpolatedMaskUV = float4((localMaskSpacePos.x + halfMaskSize.x) * invertedMaskSize.x,
                                        (localMaskSpacePos.y + halfMaskSize.y) * invertedMaskSize.y,
                                         0.0, 0.0);
        input image4 textureImage;
        input image4 textureMaskImage;
        parameter float4 color;
        output float4 result;
        void evaluateFragment()
              // just visualize the uv-coords
              result = float4(interpolatedMaskUV.x, interpolatedMaskUV.y, 0.0, 1.0);
            float4 texel = sample(textureImage, float2(interpolatedUV.x, interpolatedUV.y), PB3D_2D | PB3D_MIPNEAREST | PB3D_CLAMP);
            float4 texel2 = sample(textureMaskImage, float2(interpolatedMaskUV.x, interpolatedMaskUV.y), PB3D_2D | PB3D_MIPNEAREST | PB3D_CLAMP);
            result = float4(texel.r * color.r,
                            texel.g * color.g,
                            texel.b * color.b,
                            texel.a * color.a * texel2.a);
    I know that we're working with a four month old version of pb3d and I hope that a new version will be out soon and maybe all these bugs I encountered are already solved, but if not.... here's another shader to fix

    Ah that's interesting. I thought after compiling the three shaders with pixelbender, the two vertex kernels are merged and I can use the same parameters. This would mean, I have to push objectToClipSpaceTransform twice (with a different name)? So I would to waste four registers
    Here is the AGAL version of the shader, it's working as expected:
    vertex:
    m44 vt0, va0, vc0                   // vertex * clipspace
    m44 vt1, vt0, vc4                   // clipsace to local pos in mask
    add vt1.xy, vt1.xy, vc8.xy     // add half masksize to local pos
    div vt1.xy, vt1.xy, vc8.zw     // local pos / masksize
    mov v0, va1                         // copy uv
    mov v1, vt1                         // copy mask uv
    mov op, vt0                         // output position
    fragment:
    mov ft0, v0                                                   // get interpolated uv coords
    tex ft1, ft0, fs0 <2d,clamp,linear,nomip>      // sample texture
    mul ft1, ft1, fc0                                             // mult with color
    mov ft2, v1                                                   // get interpolated uv coords for mask
    tex ft3, ft2, fs1 <2d,clamp,linear,nomip>      // sample mask
    mul ft1, ft1, ft3                                             // mult mask color with tex color
    mov oc, ft1                                                   // output color
    The full source code here: https://github.com/nulldesign/nd2d/blob/master/src/de/nulldesign/nd2d/materials/Sprite2DMa skMaterial.as
    I'll try it with a different parameter name now. Thanks

  • Purchase order and rfq  smartforms issues

    Anyone please let me know the issues faced with purchase order and rfq smartforms

    Problems I had is changed line items to print a changed PO/RFQ wich will print what was changed with each line.
    Can't remember the solution in total. If you search on the FM ME_READ_CHANGES_EINKBELEG in the main program of the SAP standard and setup a default PO to print using the standard program and form medruck you can debug it.
    There is a change flag when printing the form, field - NAST-AENDE.
    Else the form is very much streight forward.
    Regards,
    Marius

  • Sale order doesn;t exist issue in APO

    Hi ,
    I am facing issue while trying ot create outbound delivery from sale order. But during delivery creation , BAPI_OUTB_DELIVERY_CREATE_SLS , bapi throws error as " SALE order xxxxxxxxx doesn't exist in APO , Only 0 EA of material is available..." . But when manually do, delivey is created . Hence we analysed it is due to the time taken by APO system to update the Sale order. 
    Let me know how to get the sale order or orderid in terms of APO to verify the SO is updated in APO system .
    Kindly suggest

    Dear Experts,
    this message assumed answered, I'm facing with a similar problem, during the replication of business partners the address isn't created in SAP ECC, and a bdow with the error appears.
    Thanks in advance
    Cris

  • Limit Order Confirmation Reversal - Balancing Issues

    Hello,
    We currently use SRM 5.5 and have an issue with the balances on our goods receipts and service entries for limit orders.
    We use ML81N to reverse off our service entry sheets but it is still leaving balances on the goods receipt which appears to be caused by the invoice values.
    For example we have a limit PO that has had the following happen:
    Confirmation posted in SRM for £3390.00 which transferred successfully to the backend PO.
    Invoice posted for £3371.70
    Service entry revoked and deleted using ML81Nu2013 SEN balance is zero
    Goods receipt balance is £18.30, only the value of £3371.70 has been reversed but before saving the service entry reversal the value in ML81N did show as £3390.00. So for some reason it is picking up the invoice value and reversing that instead of the goods receipt value.
    Does anyone know why this is happening and a way to get rid of the balance on the goods receipt now that the service entry sheet is deleted?
    Thanks
    Lisa

    Hi. This is probably more of a LIV / MM issue than SRM, but transaction MR11 will clear the GR/IR imbalance for you if there is no other way. It effectively posts a document like a dummy GR or invoice for the balance. It obviously won't try and pay anything to anyone.
    Regards,
    Dave.

  • Confirmation of Production order with out goods issue

    Dear All
    In one of the post the solution is given as below.
    "<b>Try using user exit "EXIT_SAPLCORF_102" to check goods issue at the time of confirmation using CO11N.</b>"
    But ..
    1. How and where to find this user exit
    2. What code to add inside this user exit like looping, condition and so on.
    Please help us, as <b>we do not have sufficient exposure in user exit</b>
    Thanks in advance
    Raj

    Hi Raj,
    I will guide to see the user exit.
    Use T.code co11n & the production order no. & enter.
    Goto the menu, choose the system status & double click the program name(GUI).
    This will take you to another screen, got to menu & choose variant. From here you can get the package name.
    Use T.code SMOD, give a name eg.ZABC & press F4, remove ZABC & enter the package name & press enter, you can see a list of user exits for this screen. Note down your user exit & then use T.code CMOD & give a name Eg.ZPP1 , then create.
    Press save local object & then press enhancements, enter the user exit name you had noted down from SMOD transaction. This will take you to the program screen.
    Here you can see the include program.
    Double click the include program & add the new codes you need. Reg. Coding pl. refer to ABAP consultant.
    Regards,
    Senthilkumar SD

  • Need to capture Vendor code & Service Order no during Goods Issue

    We have a typical req of tracking Goods issued to contractors to whom Service Orders ( Labour jobs ) is awarded. Even though contract is pure labour type , we intend to track materials issued against work orders.Std transaction of Goods issue to Purchase order can not be done here as materials are already lying in stocks but when issue to Contractor who is working in our premises , we need to track Goods issue against Work Order no in SAP as well as Vendor code , If these things get captured , we will customise the report.
    Umesh Bagul

    Hi,
    You can make Goods issue from MIGO with Movement Type-261.
    Capture the details as follows
    MIGO -> Goods Issue > Other > 261
    Maintain Work Order Number in Material Slip
    And the maintain Vendor code in Partner Details ,you can find this tab under Item detail field.Field name -Vendor Code
    THen there is no need to make seprate Z report.
    You can find all these details through MB51.
    Regards,
    Sandesh Sawant

Maybe you are looking for

  • How can I proactively prevent A/V stutter before starting a project?

    For the teeming masses who have iMovie projects that won't playback without stutter, there are several great solutions spelled out here in "Stutter in iMovie 5 & 6 - causes and workarounds": http://discussions.apple.com/thread.jspa?messageID=2597033#

  • Extraction of Open Activities from CRM (CRM t-code S_AE2_89000019)

    Hi Experts, we are to extract data from CRM, in detail the data is about open activities. However it is not pretty clear to me if there does exist SAP content for this requirement (DataSource, InfoSource, DSO, InfoCube etc). The t-code we can use to

  • Fast Change function to change plants in sales order

    Hi All, Once the plant is determined in sales order, thru the option "edit fast change-->plants", one can change the plants at line item level. my issue is Iam using a BOM material in sales order. In the line item, the main material has plant 3019 an

  • Y-axis label when printing CNiGraph using PS comes out as black square

    Hi, when printing CNiGraphs on a printer using PostScript the Y-axis lables come out as black squares (picture attached). On screen everything looks fine and they print nicely when using PCL. Does anyone have any ideas on why this happens or what mig

  • Automatically suspend when all users are idle

    Hello, I have not been able to find a way of checking if *all* users on the system are idle, and then suspending if they've been idle for a certain amount of time.  Of course individual users might have the ability to set up sleep if they want, but I