Procedure for order by

Hi,
create table test_table (
RID number,
STARTID number,
ENDID number,
ID number);
say im having some 1000 records in this table i need to fetch on the basis of param1 and param2
some times param2 might have value are might not have value
SELECT RID, STARTID, ENDID, ID FROM test_table ;
DECLARE param1 number :=1;
param2 number;
begin
SELECT RID, STARTID, ENDID, ID FROM test_table order by <param1>;
end;
Need to create SP for the above mention condition
Thanks!

The closest I can think of, based on the poor requirements given would be something like...
SQL> var param1 number
SQL> var param2 number
SQL> exec :param1 := 5
PL/SQL procedure successfully completed.At this point param2 is null, so selecting our data...
SQL> ed
Wrote file afiedt.buf
  1* select * from emp order by case when :param2 is not null then decode(:param1,1,empno,2,ename,5,to_char(hiredate,'J')) else null end
SQL> /
     EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
      7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
      7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
      7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
      7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
      7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
14 rows selected.doesn't apply any order to our results
Now if we set param2 to a non null value...
SQL> exec :param2 := 1;
PL/SQL procedure successfully completed.
SQL> select * from emp order by case when :param2 is not null then decode(:param1,1,empno,2,ename,5,to_char(hiredate,'J')) else null end
  2  /
     EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
      7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
      7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
      7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
      7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
      7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
      7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
      7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
      7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
14 rows selected.The data becomes ordered based on the value in param1, as we've defined.

Similar Messages

  • Pricing procedure for order with reference from order

    Dear Friends,
    If I create a sales order with reference to another sales order of different type, the pricing procedure is copied too.
    But I would to use another pricing procedure for second document
    I found the oss note 14136 but this is for reference from invoce
    I tried to create new data transfer routine for orders in copy from 51, but does not work
    Can you help me??
    thanks
    best regards
    GdA

    > If I create a sales order with reference to another sales order of different type, the pricing procedure is copied too. But I would to use another pricing procedure for second document,
    Based on my understanding of query.
    You are looking for a different pricing procedure in second doc.
    For instance, the PricProc for SalesDoc1 is ZPR001 and  the PricProc for SalesDoc2 is ZPR002, in addition to that, you want SalesDoc1 to become reference doc for SalesDoc2.
    For this, ZPR002 & ZPR001 should have common base price condition type and rest pricing can change.
    And for maintaining different Pricing Procedure with similar combination of sales area for SalesDoc1 & SalesDoc2, maintain different document pricing procedure for both docs and maintain Pricing procedure accordingly..
    Thanks & Regards
    J Prakash

  • Different pricing procedure for order document and billing document

    In which scenerio order and billing has diffrent pricing procedure?

    Hi,
    intercompany billing is one of the scenario.
    Business case: -
    Customer orders goods to company code/Sales organization A (Eg.4211/4211).Sales org 4211 will accept and punch the order in the system with sold to party as end customer code in the system. Company code/sales org B (Eg.4436) will deliver the goods to end customer and raise an intercom any billing on 4211 with reference to delivery. This can happen only after 4211 raises invoice to his end customer to whom the material has been delivered by 4436.
    SPRO Customization required:-
    1. Assign plant of delivering company code (Eg.SI81) to sales org/distribution channel combination of ordering company code (Eg.4211/RT)
    2. Maintain intercom any billing type as IV for sales document type OR
    3. Assign Organizational Units By Plant (Eg.SI81/4211/RT/11)
    4.Define Internal Customer Number By Sales Organization (Eg.4436 will create customer master for 4211 company code and that number will be maintained in this relationship:-4211/231)
    5. Automatic posting to vendor account (Optional)
    6. Maintain pricing procedure determination for 4211/RT/A/1/RVAA01-For customer sales and billing
    Maintain pricing procedure determination for 4436/RT/A/1/ICAA01-For intercompony billing
    Master data to be maintained:-
    1. Create end customer master in company code/sales org 4211/RT/11
    2. Create customer master for 4211 company code/sales org in 4436/RT/11
    3. Maintain PR00 as price for end customer-Active in RVAA01
    4. Maintain PI01 as price which has to be paid to 4436-Statistical in RVAA01
    5. Maintain IV01 as inter-company Price-Active in ICAA01
    Process:-
    1. Create OR with sold to party as end customer.
    2. Plant to be selected is delivering plant belonging to different company code. With this selection system will treat this order as intercomany sales.
    3. Pricing procedure is RVAA01
    4. With reference to this order delivery will be created from the delivering plant and post the goods issue for this delivery.
    5. Ordering sales org will create billing document F2 with reference to delivery for end customer.
    6. Delivering sales org will create intercompany billing IV with reference to delivery document.
    I hope this helps you.Reward points if solution is useful.
    Regards,
    Amrish Purohit

  • Diff pricing procedure for invoice and sales order?

    can u please help me out in the following question
    Is it possible to have different pricing procedure for sales order and invoice?

    hi venkat,
    yes we can very well have different pricing procedures for order and invoice. for the combination of
    sales org + dist chan + div + <b>document pric proc</b> + cust pric proc --- > Pric Proc.
    we determine the pric procedure. So, just have a different document pricing procedure for sales order document type and invoice document type. You can have a different pricing procedure with this change.
    Hope it helps. Pl reward if useful.
    Thanks
    Sadhu Kishore

  • Different Tax base in pricing procedure for a single sales order for different line item material.

    Hi,
    I have a scenario wherein in a sales order, for two different material, the tax base of pricing should get triggered on the basis of sold to party and the material entered at line item level.
    Logic triggers on the basis of Region of Customer & a unique field in the Material Master but problem comes in the calculation of Tax base as the sequence of condition type (from – to)  is already defined in the pricing procedure to pick from a particular step but in second line item the base is different i.e. the sequence of condition types that are maintained in pricing procedure should be different for Tax to calculate differently.
    Kindly suggest if the same can be handled in a single pricing procedure and dynamically taking care of condition type sequence through Alt Cal Base Formula, so far I’ve tried both Alt Cal Formula & Base but it is not working
    Client doesn’t want to go ahead by creating two different orders (through separate Pricing Procedure) for that. They want to have both materials in same order.
    Kindly suggest a suitable way to handle this scenario.
    Regards,
    Aashika Agarwal

    Hi,
    Click on the ''check availability'' button at item overview and then click on ''One-time delivery'' on the top. This will ensure that you will have only one delivery for whatever quantity is confirmed on that date.
    If you want to apply this rule for all orders across a sales area, then you can do the below configuration step :
    SPRO->sales and distribution->basic functions->availability check with ATP logic->Define default settings-> Here in avail. checking rule select A (one time delivery). This will ensure that all orders created for a particular sales area will have only one delivery.
    Hope this helps.
    Regards,
    Palani

  • Excise Pricing procedure for Stock Transport Order in MM  with TAXINN

    I am an SD guy running STO  from manufacturing plant to sales depot
    AND not able to create JEX proforma excise invoice from NL
    to TEST my configuration, I created excise invoice in J1IS with respect to goods issue from NL from UB  means configuration is ok
    BUT base amount in J1IS is coming as zero because of missing excise conditions in MM  STO pricing procedure
    CAN anybody give me a sample EXCISE pricing procedure for STO
    AND  do i need to create records for the condition types in FV11 OR  MEK1 please clarify
    I know that calculation type 362 attached to BASB in TAXINN has something to do with this
    I am able to see chapter ID in J1IS
    And the relation between condition types in TAXINN and excise pricing procedure for STO
    And I am able to create excise invoice in J1IG with zero excise values
    I also maintained pricing procedure determination for JEX in OVKK that is document pricing procedure N pricing procedure JINSTOCK
    I think my explanation is sufficient enough
    please give A sample of TAXINN

    Hi Yoga,
    Here u not need to do VL10b.just follow this steps and try.
    In PO,Document type is UB and Item Category is U.
    After creating PO,In MB!B with reference that PO number and using movt type 541
    then u can see that stock in Transit.Now u do GR with respect to PO number.
    Thanks & Regards
    Suresh.
    > Hello MM Gurus,
    >
    > I am doing Stock transport order between 2 plants
    > under same company code.
    > I have maintained all the required settings.Following
    > is the process flow.
    >
    > 1.Creation of Purchase order with document type
    > UB.(ME21N)
    > 2.Creation of outbound delivery with respect to
    > Purchase order.(VL10B)
    > 3.Post Goods Issue from the supplying plant. (VL02N)
    > 4.Creation of Excise Invoice in supplying plant.
    > (J1IS)
    > 5.Goods receipt at the receiving plant.(MIGO)
    >
    > While I am doing Goods receipt in the receiving
    > plant, system is giving an error
    > message "Maintain Vendor for the Excise Invoice" -
    > Message no. 4F185.
    > Why this message is coming and how to resolve this?
    >
    > Thanks & Regards
    > Yoga

  • Stored Procedure for lead code to be entered in sales order

    Hi All,
    I was trying to work on stored procedure for lead code not to be allowed to enter in sales order.
    It is system behaviour that it is allowing to take even lead code in sales order and add the transaction but my customer wants to block if any one of you could help me out to develop stored procedure.
    Thanks & regards-
    Monika

    Hi Monika,
    Try:
    If @object_type='17' and @transaction_type IN ('A','U')
    BEGIN
    If Exists (Select T0.DocEntry from ORDR
    Where T0.CardCode IN (SELECT CardCode FROM OCRD WHERE CardType = 'L')
    And T0.DocEntry = @list_of_cols_val_tab_del)
    Begin
    Select @error = 17, @error_message = 'Lead is not allowed for Sales Order'
    End
    END
    Thanks,
    Gordon

  • Kindly explain the step by step procedure for configuring sales order stock

    Hi friends,
    can anybody explain the step by step procedure for configuring sales order stock.
    Stock that is used for a sales order. It is directly allocated to a sales order. Components can only be used to produce material ordered by the customer and the finished product can only be delivered to the customer via the sales order.
    You can manage valuated or non-valuated sales order stock.
    If the sales order stock is not valuated, it is managed via a cost collector. The system does not carry out invoice verification postings for goods movements, and you cannot obtain an overview of how the stock is valuated until the end of the settlement period in Controlling.
    If the sales order stock is valuated, you have immediate access to its value in Financial Accounting. The assigned accounts are debited and credited as a result of the valuated goods movements.
    but i am not clear of how to map it into sap.kindly explain it step by step.
    regards,
    willaims

    Follow the link
    this will explain about complete config
    http://help.sap.com/bp_bblibrary/600/Documentation/V4J_BB_ConfigGuide_EN_US.doc

  • Pricing Procedure for Stock Transport Order

    Can anybody explain me that where can i maintain the Pricing Procedure for Stock Transport Order, Please Reply me .

    Hi Sairam,
    I am facing a similar problem.
    Can you please guide me as to where I can maintain the price in STPO. I will be raising the STPO on an intercompany plant to get a (sort of ) subcontracting done.
    I want to maintain the prices for the processing done by that plant. However, goods will be provided by us against the STPO and then receive them back after the work is done.
    Any help on this is welcome.
    Thanks
    Anshuman

  • Approval Procedure for Sale Orders

    Hi Experts:
    Anyone can help me?...I´m needing an Approval Procedure for Sale Orders to be activated whenever the user is trying to give diferent discount percentage from the one assigned in the price list throughout Period Discounts. We have Sap Business One 2007A SP01 PL05
    Thanks very much in advance
    CLAUDIA

    Hi CLAUDIA,
    This has to be done through user query approval.  However, since I don't have similar environment to try, you may start to create your own query first.
    Thanks,
    Gordon

  • Procedure for Returns for Purchase order

    Dear all ,
    can any one please let me know the complete procedure for returns for purchse orders
    Edited by: Csaba Szommer on Dec 21, 2011 6:51 AM

    Hi,
    If return involved without excise and taxes, then create of PO(ME21N), Enter Co. Code, Pur. Group, Purchase Organization, material number, quantity, plant & select Return Indicator & save.
    Carry out transaction for return in t.code MIGO or MB01 with 161 movement type and then do Credit memo in MIRO t.code.
    If excises involved , then add entry of 161 movement type for capturing Excise in following path:
    SPRO --- >Logistics general -- -> tax on Goods Movements-- ->India --- > Business Transactions -- ->Specify Which Movement Types Involve Excise Invoices
    And check link for details:
    posting of return po's excise invoice
    Regards,
    Biju K

  • Release procedure for Purchase orders

    Hello SAP Gurus,
    Can anyone explain in steps the release procedure for purchase orders and also can any one explain how it differs from Puchase requisition release procedure.
    Thanks
    NDS

    Hi
    Release procedure for Purchase orders here is process flow.
    Go to spro>img>materials management>purchassing>Release procedure for Purchase orders
    1. Create characterstics  -Intially you will create characterstics based on which you would like to release a purchase order.
    Charactrestics are like plant, purchase order value,purchase group etc.. Assign characterstics to release class 032.
    2. Create Release group say 01 and create release codes like pm(project manager), gm(general manager) etcc..
    3.  Create a Release starategy say s1 and assign release group to it 01 and release class 032 and department to whom this release stategy applies say MM. define the order of release say first pm followed by gm etc..
    4.  under classfication define value limits for release of purchase order.
    5. define release indicators
    6. simulate the release
    7. assign if there is any workflow.
    hope it helps.

  • T.Code for Release Procedure for Purchase Order Type

    Hi Frd
    im working in ECC 6.0.
    OMGS is t.code for Release Procedure for Purchase Order Type in SAP 4.6.
    Can anyone tell me what is the t.code for Release Procedure for Purchase Order Type in ECC 6.0 .the OMGS t.code is not working in ECC.
    Thanks
    By
    Pari

    Hi Rajasekharan,
        Go to tcode ME22 and enter the Purchase order number.
    inside the Display screen,u can see a GREEN flag button on the Application Toolbar.
        Click on a item and press the Green Button.
    U will see the release code,provided the Purchase order is set to release strategy,after that Go to tocde ME28 enter the release code ,along with Document number and then release the Purchase order.
    Actually the tcode for releasing purchase order is ME28
    Reward points if useful.
    Cheers,
    Swamy Kunche

  • Define Release Procedure for Purchase Orders

    Hi Friends,
    We are changing Release procedure for purchase orders for one department from > $ 5000 to > $ 10000.
    We defined three characteristics for the class namely Purchasing Order Document, Purchasing Order Type and Ner Order Value which is Currency data type. I Defined Release Procedure for Purchase Orders in configuration master. It's working fine, I mean the Net order Value field is updated in Configuration Client.
    After transporting the above change to the Testing Client, the Net Order Value field did not update in testing Client even though I created Characteristics in Testing Client (as characters are not transportable, I created them seperately in Testing Client). I can't update the Net Order Value manually in Testing Client as it says "Client 010 (test) has status 'not modifiable' "
    Please tell me how to update that field, as the net order value didn't change even after transport. I can't change manually in testing Client as the status is "not modifiable"

    Hi,
    Yes I have already done that.
    In SPRO,
    After hitting the following:-
    MM --> Purchasing --> Purchase Order --> Release Procedure for Purchase Orders --> Define Release procedre for Purchase Orders
    I have to process the objects in the following sequence,
    Release Group, Release Code, Release Indicator, Release Strategy & Workflow.
    Upto Release Indicator it is fine. After hitting Release Strategy, I should select the release strategy (which I just created) and display. Then 4 buttons will be displayed namely,
    Release Prerequisites, Release statuses, Classification, Release simulation.
    Upto Release statuses it's fine. Afeter hitting Classification,
    the values of Purchase document & Order type are populated, but the Total Net Order Value is Blank. It is supposed to populate the amount & 10,000. But it is not.
    Actually that amount will be stored in the field GNETW of table CEKKO. But CEKKO is a Structure not a table. So I can't update the field.
    Please advice me...
    Thank You,
    Nag

  • Creating business process procedure document for order creation& uploading

    Hi,
    How to create business process procedure document for order creation & upload in the same process node.
    which T-Codes I need to use?
    I have completed following things;
    1) Created Implementation Project
    2) Included order creation business process in the project.
    Regds
    PK

    Hi,
    Chk out these links.
    https://websmp202.sap-ag.de/~sapdownload/011000358700002006042008E/HowTo_Impl_Bus_Proc.pdf
    https://websmp207.sap-ag.de/~sapidb/011000358700006935382005E.sim

Maybe you are looking for

  • IPhoto Won't Import JPGs from Photoshop CS2

    Hello, I find that if I save a JPG from PS CS2, it will open in Preview, and other applications, but will not import to iPhoto. I have read the other posts here on this topic, but they have not addressed my experience. For me, it does not matter whet

  • Description issue: Role Import in CUP from ERM

    Hi All While importing roles from ERM in CUP, the description column shows some numeric values in some strange sequence (like 0,1,10,100,1000,1001,1002,1003, and so on). In ERM, roles were uploaded from backend using Mass role Import and Role descrip

  • Release status for condition records

    Hello, When ever a user changes the price in the condition record, I want the price to be in blocked status initially. Sales document should only pick tht price when it is release by the concerned person. Could you tell me how is the authorization gi

  • Prefetch Error with MMAPI

    hai Guys,,im so sorry if this thread already post..<but i dont find it here until 2x or more page> did anyone know this ? I got an error ( prefetch error: -5 or prefetch error: -2 ) when trying to run the code to play video format 3gpp with MMAPI. i

  • How much drive space for FCS 2

    How big is FCS 2 and can it be installed on a external hard drive instead of on the computer?