User Defined Query Result Ordering ???

I have a problem in Ordering my query to desired result.
Example : In my WHERE clause I specify IN operator and give some values (Integer) : I want the result to be in the same order what I have specified in the In operator values ?.
Faheem

You can use a Decode in the order by clause
e.g.
select * from table
where field1 in ('d', 'a', 'c', 'b')
order by decode(field1, 'd', 1, 'a', 2, 'c', 3, 'b', 4)
I have a problem in Ordering my query to desired result.
Example : In my WHERE clause I specify IN operator and give some values (Integer) : I want the result to be in the same order what I have specified in the In operator values ?.
Faheem

Similar Messages

  • PLD report from user defined query

    Hello experts,
    Is possible to create a new PLD report from a user defined query ?
    Thanks in advance.
    Best regards
    Andrea

    Hi,
    It is possible on Query Print Layout Design(QPLD) so Try to create QPLD.
    Check this link u can get presentation slide form SAP.
    [Query Pld from SAP site]
    First you can try to create the Query report with UDF filed.
    for example,
    SELECT T0.DocNum, T0.DocDate, T0.CardName, T0.CheckSum, T0.U_UDF1, T0.U_UDF2, T0.U_UDF3
    FROM OVPM T0 WHERE T0.DocNum>='%0' and T0.DocNum<='%1' ORDER BY T0.DocNum
    Steps to Develop a User Report in QPLD:-
    If you save your Query in Query Manager. Next you can do this,
    ->> Choose the Query Manager on Top Menu.
    ->> Open the Qeury Manager Window.
    ->> Select the specific Query report. and
    ->> Click the Create Report button in Bottom on Qeury Manager Window.
    ->> then, Open the Create User Report Window and Select the User Report(System) in Base Template.
    If you Change the QPLD name.
    ->> Click OK.
    ->> (or) If your Query Report have parameter. Click OK.
    Now your Query report was Created QPLD.
    Note: All SELECT statement fields will be Stored and Display in Repetetive Area1. and
    Parameter Fields are in Repetetive Area0 so you can Try to Copy & Paste the Field_ID's to Repetetive Area Header (or) Repetetive Area Footer.
    Example:
    ->> Open the QPLD and Goto Field index Window, then
    ->> Select the Repetetive Area Header & Repetetive Area Footer ncrease the Height on Properties Window.
    ->> Create the Formula fields in Repetetive Area Header & Repetetive Area Footer.
    ->> Which Field you want to print in header or footer. Drag the Field ID(in Repetetive Area) Copy & Paste to Formula Field.
    Can you see to your Query PLD? do this,
    ->> Choose the Tools on Top Menu.
    ->> Click the Queries. -> Query Print Layout...
    ->> Open the Query Print Layout Window.
    ->> Click Reports Tab and Double the Template (Requrie QPLD) on QPLD Window.
    ->> Customize and Save the QPLD.
    Can you see your Query PLD Preveiw and Print? do this,
    ->> Choose the Tools on Top Menu.
    ->> Click the Queries. -> Query Print Layout...
    ->> Open the Query Print Layout Window.
    ->> Select Template in Report Tab on QPLD Window.
    ->> Click Print Preview on Top menu.
    Close this thread if issue solved
    Regards,
    Madhan.

  • User defined query parameter in query generator

    Hi All,
    i am using query generator in SAP to print some records of user defined query. precisely, the details about sales employees are to be printed. now the columns which exist in the database (ie. sales employee code, name, cardcode) etc can be given as a parameter like [%0] and [%1]. but some user defined parameter such as sales commission does not show as such parameter. i want one column as
    select T0.doctotal, (T0.doctotal * [%0]) / 100  as brokerage from OINV T0
    --where [%0] is some commission percentage that the user will give while running this query
    This query gives correct results but it gives the parameter name as 'doctotal' while showing. any idea as to how to handle it properly in SAP?
    thanks in advance,
    Binita
    Edited by: Binita  Joshi on Sep 8, 2009 3:35 PM

    I sometimes defined a UDT only for getting the appropriate parameter entering window. The table has no data; I used it only for its field names in this window.
    (The parameter request can be placed inside a comment and the entered value is used setting an SQL variable like this:
    declare @d datetime
    /*select t.createdate from ordr t where t.createdate=[%0]*/
    set @d=[%0]
    This SQL variable can be used later in the real query.)

  • User defined query parameter in QLD

    Hi All,
    i am using query generator in SAP to print some records of user defined query. precisely, the details about sales employees are to be printed. now the columns which exist in the database (ie. sales employee code, name, cardcode) etc can be given as a parameter like %0 and %1. but some user defined parameter such as sales commission does not show as such parameter. i want one column as
    select T0.doctotal, (T0.doctotal * [%0]) / 100  as brokerage from OINV T0
    --where [%0] is some commission percentage that the user will give while running this query
    This query gives correct results but it gives the parameter name as 'doctotal' while showing. also, when I join 4-5 tables and union, it totally misinterprets the paramater. any idea as to how to handle it properly in SAP?
    thanks in advance,
    Binita

    Hi
    I know it list many value but u can try by this way....
    declare @a numeric(3)
    set @a = (select  top 100 docnum from oinv T1 where T1.[docnum]= [%0])
    select T0.doctotal, (T0.doctotal * @a) / 100 as brokerage from OINV T0
    Thanks
    Kevin

  • User defined Query in Print Layout

    Is it possible to print output of a user defined query in a Print Layout. For example: in Quotation
    Kentish

    Thanks for your input.
    But its not related to Query Print Layout. I wanted to print a query result in a Sales Quotation so that when you print the Sales Quotation, you get the result of the Query on the Sales Quotation
    Thanks
    Kentish

  • Prevent user defined query from being activated with the CopyTo function

    Hi, I have a user defined query defined in one of the quantity field (in the grid) in the goods receipt PO window.
    The query updates the quantity depending on the number of another line field. The query works great, but I dont want it to be activated when a user clicks the "Copy From" purchase order. When this happens the query gets activated and changes the quantity.
    The query is defined to be activated "when exiting altered column", i have not selected the "Refresh Regulary"
    Please help!

    Thank you so much for replying,
    this is my query, depending on the column U_Empaque (type of package), I look for the right conversion in the OITM table of the item. Then I use the number from the column U_Cantidad_Empaque (Quantity Of the Type of package) to multiply by the conversion factor that I have defined for the Item in the OITM user fields. The conversion is a standard conversion, so It needs to be modified by the user to set it to the real quantity of the unit of measure (or unit of inventory). The query works great, except for the CopyTo and CopyFrom functions.
    Iam using 2007 A patch 45.
    México's settings.
    SELECT
    CASE
    WHEN (SELECT 'TRUE' FROM OITM T0 WHERE T0.ITEMCODE = $[$38.1.0] AND T0.U_EMPAQUE1 = $[$38.U_Empaque.0]) = 'True' THEN (SELECT ($[$38.U_Cantidad_Empaque.0]) * T1.U_CONVERSION1 AS 'Respuesta' FROM OITM T1 WHERE T1.ITEMCODE = $[$38.1.0] AND T1.U_EMPAQUE1 = $[$38.U_Empaque.0])
    WHEN (SELECT 'TRUE' FROM OITM T0 WHERE T0.ITEMCODE = $[$38.1.0] AND T0.U_EMPAQUE2 = $[$38.U_Empaque.0]) = 'True' THEN (SELECT ($[$38.U_Cantidad_Empaque.0]) * T1.U_CONVERSION2 AS 'Respuesta' FROM OITM T1 WHERE T1.ITEMCODE = $[$38.1.0] AND T1.U_EMPAQUE2 = $[$38.U_Empaque.0])
    WHEN (SELECT 'TRUE' FROM OITM T0 WHERE T0.ITEMCODE = $[$38.1.0] AND T0.U_EMPAQUE3 = $[$38.U_Empaque.0]) = 'True' THEN (SELECT ($[$38.U_Cantidad_Empaque.0]) * T1.U_CONVERSION3 AS 'Respuesta' FROM OITM T1 WHERE T1.ITEMCODE = $[$38.1.0] AND T1.U_EMPAQUE3 = $[$38.U_Empaque.0])
    WHEN (SELECT 'TRUE' FROM OITM T0 WHERE T0.ITEMCODE = $[$38.1.0] AND T0.U_EMPAQUE4 = $[$38.U_Empaque.0]) = 'True' THEN (SELECT ($[$38.U_Cantidad_Empaque.0]) * T1.U_CONVERSION4 AS 'Respuesta' FROM OITM T1 WHERE T1.ITEMCODE = $[$38.1.0] AND T1.U_EMPAQUE4 = $[$38.U_Empaque.0])
    END

  • Standard report for User defined feild in order operation

    Hi all,
    do we have any standard report? for User defined field in order operation. actually we have User defined field in task list and same could be reflected in order operation. so i am using those user defied field to record extra info in maintenance order.  i am wondering how to get the reports . do we have any standard reports?
    thanks
    Amit kushwaha

    Dear Amit
    I have utilised 3 user fields & activated order enhancement tab. I could find these three fields in report IW37N & IW49N. I m using ECC 6.0 EHP4. Try to set the layout & look for  fields - user field for quantity in the layout. For this please maintain some data in these user fields of some orders and then check for those orders in t code- IW37N & IW49n.
    Shakti

  • Hide our user defined query

    Dear All Master Brains,
    It is possible to hide our user defined query in Query Manager, apart from our user authorization.
    I am waiting for your …………..
    Regards,
    Team work never fails.

    Hi,
    Only by authorizations you can hide the user queries.
    Alternate way, If you have created those query for report purpose then you convert that query into QPLD, So that users cannot view the query you developed instead they can view the report alone.
    I hope this could help you.
    Regards
    Raja.S

  • User-defined function in order by?

    Hey guys.  We're trying to port our postgres db to Oracle, and I'm stumbling on this one issue.  We have columns called 'sortSequences', which are arbitrarily long arrays of integers.  For POC purposes, I am using varray(), but that probably won't work as an production implementation, because of it's strongly-defined size.  Anyway, the crux of the problem is that I need to be able to select * from foo order by sortSequence, where the ordering evaluation is custom code.  The array of integers essentially represent infinite-precision math, and we have a deterministic algorithm for comparing them, but one cannot simply produce a value from them (which I think prevents me from using a map member function in a user-defined object type.)  In other words, we don't really care what the values are, we are just using them collectively as a sorting index.  An aggregate function didn't look like the right answer, and a simple scalar function is out of the question.  We were looking at domain indexes, but it's not clear to me that even if we created an operator bound to our user-defined type that the db would use that function for order by evaluation...
    Can anybody think of a solution for this problem?  If we absolutely have to live without this functionality, we can replicate it in app code, but we wish to avoid that at all costs...
    thanks,
    brian

    Doesn't look very promising for a general case.
    Even for short sequences and moderate number values the computed numbers to order by are quite large.
    with
    data_table as
    (select '[10,1,1]' csv from dual union all
    select '[1,5,-1]' from dual union all
    select '[1,1,1,1]' from dual union all
    select '[3,-5,1,3,2]' from dual union all
    select '[1,1,2]' from dual union all
    select '[1,20]' from dual union all
    select '[2]' from dual union all
    select '[1,7,1]' from dual
    mapped as
    (select csv,
            lvl,
            item - min(item) over (order by null rows between unbounded preceding and unbounded following) n,
            max(item) over (order by null rows between unbounded preceding and unbounded following) -
            min(item) over (order by null rows between unbounded preceding and unbounded following) m,
            max(lvl) over (order by null rows between unbounded preceding and unbounded following) x
       from (select csv,
                    level lvl,
                    to_number(regexp_substr(t_csv,'[^,]+',1,level)) item
               from (select csv,
                            ltrim(rtrim(csv,']'),'[') t_csv
                       from data_table
             connect by level <= regexp_count(csv,',') + 1
                    and prior csv = csv
                    and prior sys_guid() is not null
    joined as
    (select l.csv,l.lvl,nvl(m.n,0) n,l.m,row_number() over (partition by l.csv order by l.lvl desc) rn
       from mapped m
            right outer join
            (select csv,lvl,m
               from (select level lvl,
                            (select max(m) from mapped) m
                               from dual
                             connect by level <= (select max(x) from mapped))
                    cross join
                    (select csv from data_table)
            ) l
         on l.csv = m.csv
        and l.lvl = m.lvl
    order by csv,lvl
    select csv,o
      from (select csv,rn,o
              from joined
             model
             partition by (csv)
             dimension by (lvl)
             measures (rn,n,m,0 o)
             rules
             (o[lvl] = (nvl(o[cv(lvl) - 1],0) + n[cv(lvl)]) * m[cv(lvl)])
    where rn = 1
    order by o
    CSV
    O
    [1,1,1,1]
    61035000
    [1,1,2]
    61046875
    [1,5,-1]
    62562500
    [1,7,1]
    63375000
    [1,20]
    68359375
    [2]
    68359375
    [3,-5,1,3,2]
    78223925
    [10,1,1]
    148921875

  • Notification with user defined type results in PLS-00306: wrong number..

    I created a user defined type TLogMessage:
    CREATE OR REPLACE TYPE TLogMessage AS OBJECT
    module VARCHAR2(4000),
    severity NUMBER,
    message VARCHAR2(4000)
    I also created a multi-consumer queue using this type as payload.
    My callback procedure in the package PK_SYST_LOGMESSAGE is defined as follows:
         PROCEDURE DefaultLoggerCallback(
              context          RAW,
              reginfo          SYS.AQ$_REG_INFO,
              descr          SYS.AQ$_DESCRIPTOR,
              payload          RAW,
              payload1     NUMBER
    Finally, I registered the callback procedure as follows:
              DBMS_AQADM.ADD_SUBSCRIBER(
                   queue_name      => QUEUE_NAME,
                   subscriber      => SYS.AQ$_AGENT(
                                            name => 'default_logger',
                                            address => NULL,
                                            protocol => NULL
              DBMS_AQ.REGISTER(
                   SYS.AQ$_REG_INFO_LIST(
                        SYS.AQ$_REG_INFO(
                             name          => QUEUE_NAME || ':default_logger',
                             namespace     => DBMS_AQ.NAMESPACE_AQ,
                             callback     => 'plsql://MTDX.PK_SYST_LOGMESSAGE.DefaultLoggerCallback',
                             context          => HEXTORAW('FF')
                   1
    However, when I put a message in the queue using this procedure:
         PROCEDURE LogMessage(
              pModule          VARCHAR2,
              pSeverity     NUMBER,
              pMessage     VARCHAR2
         IS
              vMessage               TLogMessage;
              vEnqueueOptions          DBMS_AQ.ENQUEUE_OPTIONS_T;
              vMsgProperties          DBMS_AQ.MESSAGE_PROPERTIES_T;
              vMessageHandle          RAW(16);
         BEGIN
              vMessage := TLogMessage(module => pModule, severity => pSeverity, message => pMessage);
              vEnqueueOptions.visibility := DBMS_AQ.IMMEDIATE;
              vMsgProperties.correlation := pModule;
              vMsgProperties.priority := -pSeverity;
              -- Enqueue the message to all subscribers
              DBMS_AQ.ENQUEUE(
                   queue_name               => QUEUE_NAME,
                   enqueue_options          => vEnqueueOptions,
                   message_properties     => vMsgProperties,
                   payload                    => vMessage,
                   msgid                    => vMessageHandle
         EXCEPTION
              WHEN no_subscribers THEN
                   -- No subscribers on the queue; ignore
                   NULL;
         END;
    I can see the message in the queue, by querying the queue view. I can also see that Oracle tried to call my callback procedure, because in the trace file I see the following:
    *** 2009-02-13 08:52:25.000
    *** ACTION NAME:() 2009-02-13 08:52:24.984
    *** MODULE NAME:() 2009-02-13 08:52:24.984
    *** SERVICE NAME:(SYS$USERS) 2009-02-13 08:52:24.984
    *** SESSION ID:(609.3387) 2009-02-13 08:52:24.984
    Error in PLSQL notification of msgid:4F7962FEDD3B41FA8D9538F0B38FCDD1
    Queue :"MTDX"."LOGMESSAGE_QUEUE"
    Consumer Name :DEFAULT_LOGGER
    PLSQL function :MTDX.PK_SYST_LOGMESSAGE.DefaultLoggerCallback
    : Exception Occured, Error msg:
    ORA-00604: Fout opgetreden bij recursief SQL-niveau 2.
    ORA-06550: Regel 1, kolom 7:
    PLS-00306: Onjuist aantal of type argumenten in aanroep naar 'DEFAULTLOGGERCALLBACK'..
    ORA-06550: Regel 1, kolom 7:
    PL/SQL: Statement ignored.
    So.. how many parameters does Oracle expect, and of what type? Is there any way to find out? What is wrong with my code?

    Ok, found it... I had defined the last parameter of the callback procedure as 'payload1' (that is: 'payload-ONE') instead of 'payloadl' ('payload-ELL'). It all works like a charm now.
    What a way to waste two whole days!

  • Alert based  on user defined query

    Hi
    I have defined user defined field U_Jobnumber.I need to stop /inform user if user is trying to enter the same u_Jonbnumber again .This is being done at sales order (header level)
    Can you please help me to provide solution
    (Points will be awarded based on solution or advice )
    Thank you
    Bishal

    Hi Bishal,
    Rather than using an alert, you could put validation code in the SBO_SP_TransactionNotification stored procedure to check for the same job number before the document is added. This is a permitted solution as SAP allow users to add their own sql code to this proc (provided it's not inserting or updating data in SBO system tables).
    To set up this solution (on a test system):
    1) Open SQL Studio Management
    2) In the Object Explorer expand the company database, expand Programmability and Stored Procedures
    3) Right-click the SBO_SP_TransactionNotification stored procedure and choose Modify. This will create an update script in the main window.
    4) Look for the following section in the script:
    --     ADD     YOUR     CODE     HERE
    5) Underneath the above section, paste the following code:
    if @OBJECT_TYPE = '17' and @TRANSACTION_TYPE in ('U', 'A')
         if exists(select DocEntry from ORDR where DocEntry &lt;&gt; cast(@LIST_OF_COLS_VAL_TAB_DEL as int)
                        and U_Jobnumber is not null and U_Jobnumber &lt;&gt; ''
                        and U_Jobnumber = (select U_Jobnumber from ORDR where DocEntry = cast(@LIST_OF_COLS_VAL_TAB_DEL as int)) )
              begin
                   set @ERROR = '9999' -- Set your own error code here
                   set @ERROR_MESSAGE = 'The Job Number entered has already been used on a previous sales order.'
              end
    6) Click on Execute and you should get a message stating that the update was successful
    7) Test adding a new sales order
    The above script will raise an error when the user clicks on Add if a job number has been specified on the sales order and that number has already been used. It will not check if a job number has not been specified
    Kind Regards,
    Owen

  • Dynamically create Datatable result from user defined query

    I have seen some close solutions, but not 100% for the following:
    1. JSF Datatable exists in JSP, but no columns defined
    2. Execute query and populate results to JSF with headings and data
    3. Binding this data to the Datatable
    I have managed to created column headers (facets) but can't identify how to populate the rows based on the resultset. If one does not have a resultset but rather a collection of domain objects, how does one bind the table to the displayable objects (domain) ?
    Thanks to the gifted one who leads me to enlightenment !
    -- The grass may be greener, but I'm looking for a maintenance free lawn.

    Hello,
    Congrats !!! you mamnaged to solve the problem.
    Please can you let me know how did u solve the problem as I'm also facing the same problem..
    Also another request Please can you let me know if there if any kind of good documentaion on jsf components as well as some examples.
    I'm using MyEclipse4.1
    Thanks for any help
    abhi

  • Problem regarding user defined query

    I have a problem with Formatted Search in the Item table of the Order window.
    We got some extra functionality for our Indian subsidiary and they are provided via Formatted Searches.
    So for example there is one SQL statement with mathematical computations like (don't ask! SQL is not for mathematics, i would do this with SDK!)
    snip ###
    if $[RDR1.Itemcode]= '880000000000'
    SELECT (convert(decimal(16,2),$[RDR1.U_V_Width])convert(decimal(16,2),$[RDR1.U_V_Height])convert(decimal(16,2),$[RDR1.U_Qty_Nos]))/1000000
    else
    select ((select slength1 from oitm where itemcode=$[RDR1.Itemcode]) * $[RDR1.U_Qty_Nos]) from oitm where itemcode= $[RDR1.ItemCode]
    snip ###
    The Search is defined with:
    Search by saved query
    Auto Refresh when exiting altered column Qty(Nos)
    Display saved values
    If i have only one line, all theses queries (5) are computed in just a second. But if there are 20 or more it takes 20 seconds to compute!
    It feels like all fields of all rows will be computed again if i change one of the corresponding fields!
    What can i do to minimize waiting period for the user?

    Hi Frank,
    This may be the current limiting factor in using formatted searches at the line level. There are known performance issues with using formatted searches in this way with the UI slowly grinding to a halt as the number of rows on the document increases. The situation gets worse if formatted searches are combined with an add-on that uses the validate event on row fields. Is it correct that your main company (without formatted searches) gets better performance?
    The only workaround is not to use formatted searches :-\
    I've heard the situation is better in SBO 2007A but I haven't tested it myself.
    Kind Regards,
    Owen

  • Executing user defined query

    Hi,
    I am trying to build an interface where a user will input his query(could be any query). His query is then executed and the results displayed along with the name of columns he gave in the query.
    for e.g. the user gives
    select * from dept
    the o/p shud be
    deptno dname loc
    10 ..... .....
    20 ...... .....
    How can we do this? i guess using metadata.
    Please suggest
    Ashish

    Ashish,
    There are several open-source (and commercial) projects available that already do what you are trying to achieve. You can find some on the Sourceforge Web site. Just do a search for "JDBC" and "SQL". One example is SQuirreL.
    Good Luck,
    Avi.

  • User Defined Query and Alerts

    Hello guys, I need to set up an alert that happens whenever a Sales Order or Purchase Order is added. I am happy with the alerts procedure but I cannot set up a query.
    Can anyone please help me set up queries that simply mean 'when SO added' and 'when PO added'?
    Many thanks

    OK Groovy - really glad you are following up on this.  Many financial folks like to have this kind of review (especially when they first get onto SAP B1) since it gives them a comfort level of being able to see what is done.
    Good time for you to take a look at the Query Generator and learn a bit of a new skill (PATH: Reports > Query Generator)!  Once you get the hang of it, you can be a real whiz!
    Here is the exact SQL used in their Alert Messaging System.  Type this in exactly as you see it below in the Demo or Test System just to try it out and get a hang of it...
    <b>SELECT
    T0.DocNum AS 'Doc Num',
    T0.UserSign AS 'User ID',
    T0.DocStatus AS 'Doc Status',
    T0.DocDate AS 'Post Date',
    FROM ORDR T0
    WHERE T0.DocStatus = 'O'
    ORDER BY T0.DocNum DESC</b>
    A few comments - the DocNum and UserSign fileds display the famous golden 'drill down' arrows which allow the person to take a look at the document and whoever process the transaction.
    An added bonus is that you can use this exact SQL to query many different tables and use them as their own individual alerts (for example, just substitute ORIN for ORDR and the system will display the AR Credit Memo - all the field names are the same!).
    A WORD OF CAUTION:  Remember this SQL is picking up orders with the status of 'O(pen)'.  It is very important how often you run this Alert Message because it might not report all orders created depending upon the time between order creation and SQL running to generate the alert.  Consider the following scenario: A firm has the alert come up weekly on Friday.  Monday a person creates an order 123, the warehouse ships on Tuesday.  Home office bills the order and closes it on Thursday.  When the alert message is generatedon FRIDAY, 123 will NOT be in the list since it now has a status of 'C(losed)'.  That scenario requires different 'WHERE' selection criteria dealing with dates...
    Good luck - Zal

Maybe you are looking for