Ordering/Ranking based on Character field

Hi All,
I need to ordering/Rank a column based on varchar field.
Here is my input
Create table #InputTmp
CustomerNumber Varchar(10),
AccountNumber Varchar(10)
Insert into #InputTmp
Select '1234','123121'
Union All
Select '1234','4728272'
Union All
Select '3421','3234'
Union All
Select '434','232122'
Expected output:
here because customer number is same (1234) for first records i need assign 1 to 123121 and 2 to 4728272. if the customer number is not repeating then i have populate 1 in ordering field.
I have do it without using WITH clause.
Appreciate your inputs.
Regards,
Eshwar.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

Out of curiosity, why without WITH clause?
Create table #InputTmp
CustomerNumber Varchar(10),
AccountNumber Varchar(10)
Insert into #InputTmp
Select '1234','123121'
Union All
Select '1234','4728272'
Union All
Select '3421','3234'
Union All
Select '434','232122'
select t.*
from
(SELECT *, RANK() OVER (PARTITION BY CustomerNumber ORDER BY AccountNumber) as Ordering
FROM #InputTmp t
) t
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Similar Messages

  • Purchase Order GR based Invoice varifiation Field - ACtive

    Hi,
    when ever Goods receipt field-WEPOS is active in purchase order,Delivery Tab at item level, Gr based IV should also get active - WEBRE, other wise system should not allow to save the Purchase document.
    how to control the same.
    any enhancement.....pl.. let me have...

    Hi Shirley,
    Go to Vendor master change(XK02/MK02)with whom you are creating the Framework order - Purchasing data, in that uncheck the check boxes for GR-based invoice and Goods receipt. Then save the vendor master. Then create the framework order.
    Hope this helps.
    Thanks,
    Viswanath

  • Change the sort order (ascending/descending) based on parameter field

    I have created a formula on a subreport to change sorting based on variables.
    select {?Pm-@Sorting}
    case "property_type_desc ASC" :
    {owned_property.property_type_desc}
    case "property_type_desc DESC" :
    {owned_property.property_type_desc}
    default:
    ({owned_property.property_type_cd}; )
    how can I change the sort order ascending and descending using the formula??
    Thanks, Jessica

    Try this
    1. Create a parameter with 2 default values in the picklist: Descending and Ascending.
    NOTE:
    In Crystal Reports version 5 or 6, it is not possible to have a pick a parameter value from a list. The user must enter a specific value, guided by the prompting text. For example : To Sort in Ascending order type A, to sort in Descending order type D.
    u2022 On the 'Insert' menu, click 'Parameter', then click 'New'.
    u2022 Type the name and prompting text for the parameter in the corresponding boxes.
    u2022 In the 'Type' box, click 'String'.
    u2022 Click 'Set Default'.
    u2022 In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.
    u2022 Repeat the above step for 'Ascending'.
    u2022 Click 'OK', then click 'OK' again to return to the report.
    2. Create 2 formulas based on the field you want to change the sort direction on:
    u2022 On the 'Insert' menu, click 'Formula', then click 'New'.
    u2022 Create this formula:
    @Asc
    If {?Parameter} = "Ascending" then
    u2022 Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.
    u2022 Click 'New' and create this formula:
    @Des
    If {?Parameter} = "Descending" then
    u2022 Save this formula and close the Formula Editor.
    u2022 Click 'Close' to return to the report.
    4. Sort the report based on these two formulas.
    u2022 On the 'Report' menu, click 'Sort Records'.
    u2022 In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Ascending'.
    u2022 In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Descending'.
    u2022 Click 'OK' to return to the report.
    Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.
    Regards,
    Raghavendra

  • Reg: How to view the PR on the basis of Re-order point based PR

    Hi All,
    How can i view the Purchase requisition on the basis of Re-order point based PR.
    Thanks & Regards
    Kannan Somasundaram

    Go to Transaction code ME53N
    Under Item Detail find the Tab "Contact Person "
    from that you can find Creation Indicator , which is generally B Material Requirement Planning for Re order level planning operation done through planning.
    For report You can look at transaction code : ME5A
    You can look at Table EBAN and field : ESTKZ
    Edited by: sudhansu satapathy on Mar 18, 2010 9:04 AM

  • Changing the status of the sales order item based on reason for rejection

    Hi All,
    When a Sales order item is rejected then the status at the item level is changed as 'TECO'.When the reason for rejection is removed the status 'Teco' is reset.This status change can be achieved using the user exit 'MV45AFZZ'.But the exit does not allow re-atp calculation whenver a blocked item is release.I have use the exit 'MV45AFZB' ,through this the status change as well as re-atp calculation takes place.But the status changed(Based on reason of rejection) does not appear in the same screen.The change gets reflected only when the sakes order is saved and i open it again.
    I want the status change to appear in the same screen.I am doing my code in the form 'userexit_check_vbap' of the exit 'MV45AFZB'. Please let me know if there are any user exits or BADI's available for the same(Changing the status of the sales order item based on reason for rejection ).
    Regards,
    S.Subasree

    Hi subburamaiah
    If you want the report you can create a separate SIS report . In that take the input field  as a Reason for rejection.. and ask for the output the list of sales orders .Now when you check this user defined report you will give the reason for rejection and check what all orders got rejected on that reason for rejection.
    Regards
    Srinath

  • Change order type based on sold to party

    Hi all,
    Is there any user exit to change the order type based on Sold to party.
    Eg: if any user select some sold to party during sales order creation then using sold to party the order type is changed.
    Any suggestions welcome.
    Regards,

    Hi Navadeep,
    Please try with these
    The program MV45AFZB   
    USEREXIT_CHECK_VBAK                                                     
    This user exit can be used to carry out additional checks (e.g. for     
    completion) in the document header. The system could, for example,      
    check whether certain shipping conditions are allowed for a             
    particular customer group.     
    The program MV45AFZZ                                                                               
    USEREXIT_FIELD_MODIFICATION                                        
    This user exit can be used to modify the attributes of the screen  
    fields.                                                            
    To do this, the screen fields are allocated to so-called           
    modification groups 1 - 4 and can be edited together during a      
    modification in ABAP. If a field has no field name, it cannot be   
    allocated to a group.                                              
    The usage of the field groups (modification group 1-4) is as       
    follows:                                                                               
    -   Modification group 1:   Automatic modification with transaction
        MFAW                                                                               
    -   Modification group 2:   It contains 'LOO' for step loop fields 
    -   Modification group 3:   For modifications which depend on check
        tables or on other fixed information                                                                               
    -   Modification group 4:   is not used                            
    The FORM routine is called up for every field of a screen. If you require changes to be made, you must make them in this user exit.         
    This FORM routine is called up by the module FELDAUSWAHL.                 
    See the Screen Painter manual for further information on structuring      
    the interface.                                                                               
    USEREXIT_SAVE_DOCUMENT                                                     
    Use this user exit to fill user-specific statistics update tables.         
    The user exit is called up by the FORM routine BELEG-SICHERN before        
    the COMMIT command.                                                        
    Note                                                                       
    If a standard field is changed, the field r185d-dataloss is set to         
    X. The system queries this indicator at the beginning of the safety        
    routine. This is why this indicator must also be set during the            
    maintenance of user-specific tables that are also to be saved.                                                                               
    USEREXIT_SAVE_DOCUMENT_PREPARE                                             
    Use this user exit to make certain changes or checks immediately           
    before saving a document. It is the last possibility for changing or       
    checking a document before posting.                                        
    The user exit is carried out at the beginning of the FORM routine          
    BELEG_SICHERN.  
    I hope it will help you,
    Regards,
    Murali.

  • Table of Contents based on Character Style?

    Trying to do an annotated table of contents containing captions of all photos in a book, followed by verbose descriptions. Purpose is to avoid cluttering pages bearing the photos, which will have only a brief caption is followed by the name of the owner of the object in the caption, in the same paragraph.
    Book will include a listing of the captions in page order (i.e., table of contents) without the owner names, followed by verbose descriptions. Can I get around this by making character styles for each (caption, owner, respectively), and create a TOC based one character style? If not, can I configure the para. style of the caption to omit the line-feed, and base the TOC on that?
    Plan is then manually to add descriptions to each TOC entry, immediately following captions. Will that stay intact, if any subsequent photo locations are changed?

    Jack wrote:
    OK, have done that, and all required content is now showing up in the TOC.
    I'm glad you managed to sort that out.
    Is it possible to omit the line breaks between elements referring to the same page?
    Hmmm...the thing is...a paragraph is a paragraph is a paragraph. By nature, it breaks to the next line. There are ways to fake it but none (that I can think of) which will hold up to an automated TOC update. Maybe someone else will come along with a trick I don't know about.
    So then, for the moment let's assume the only way to get the caption and the description into the same TOC paragraph is to put them in the same paragraph on the document page. Also still assuming I truly understand the end-result you want; here's how I would do it:
    If you set the separate-but-threaded caption and description frames as I first proposed, you'll need to go back and take out the paragraph break between the caption and the description. It will have to be replaced by a simple "frame break" which will push the description (now the same paragraph and paragraph style as the caption), into its own hidden frame as before.If, in the TOC, you want the caption and the description to have differing formatting, it would also be useful to insert (between the caption and the description on the document page) an End Nested Style Here character before that frame break. (If the caption and the description can be formatted identically, you won't need this step, and they can simply be formatted by your simple TOC Entry Style paragraph style.)
    All above can be done using Find/Change. Find: End of Paragraph (^p). Change to: End Nested Style Here (^h) Frame Break (^R). So here's what it looks like in the dialog.
    If the captions and descriptions are the only text in your document, you probably get away with Change All, otherwise it may be best to step through finding and changing one instance at a time.
    Now if you update your TOC, the descriptions should be pulled up into the same paragraph as the captions.
    Take advantage of the Nested Style possibility to vary the formatting of the caption and description by adding a nested style to your TOC Entry Style. Set it to style the description portion of the entry. Then add a Nested Style and set a Character Style to format the caption portion of the entry... "through 1 End Nested Style Character".

  • How to find out the Sales order no based on spool no

    Hi Experts,
    Anyone tell me how to find out the Sales order no based on Spool no.
    Thanks and regards,
    Amjad

    Hello Mohammed,
    Please check the following SAP Spool tables for your spool request.
    You will find your required document number as an Object key in these tables.
    TSCMSTAT   --> Field OBJNO
    SOOS           --> Field APPLKEY (Document number will be a part of this key)
    If your document is getting printed by SAP Script, then dont forget to take SCR value in the OBJTP field while searching for your record.
    Thanks and Best Regards,
    Vikas Bittera.
    ***Points for Usefull answers ***

  • How can i compare the character fields?

    I have a requirement to compare the character fields .
    I have to compare the 2 character fields of a table CDPOS
    As follows .
      If CDPOS-VALUE-OLD  GT  CDPOS-VALUE-NEW
          Populate    REDATED = ‘YES’.
    ELSE
          Populate  REDATED = ‘NO’.
    My doubt here is how can we compare the character fields.?
       When I do Extended Program Check: I am getting error like this ?
    Greater than/less than comparisons with character type operands may not be portable
    Please give me idea .
    Thanks ,
    Suresh Kumar.

    Hi suresh,
    DATA : a TYPE char10  VALUE 'DBCD',
           b TYPE char10  VALUE '4234',
           c TYPE char10  VALUE '3456',
           d TYPE char10  VALUE 'ADA',
           e TYPE char10 VALUE  '234567'.
    IF b GT c.        "this case checks for numeric values
      WRITE :/ 'B is bigger'.
    ELSE.
      WRITE :/ 'C is bigger'.
    ENDIF.
    IF a GT d.      "this case checks for alphbetical order
      WRITE :/ 'A is bigger'.
    ELSE.
      WRITE :/ 'D is bigger'.
    ENDIF.
    IF strlen( a ) GT strlen( d ). "this case checks for no of chars
      WRITE :/ 'A is bigger'.
    ELSE.
      WRITE :/ 'D is bigger'.
    ENDIF.
    IF a GT c.      "this case first alph then numerics
      WRITE :/ 'A is bigger'.
    ELSE.
      WRITE :/ 'D is bigger'.
    ENDIF.

  • Character field with date format alike & character entered

    Hi all,
    I got one character field created ( varchar2 ) for the purposed to let user the enter the date and also any character since it is a character field.
    Hence, my field may contain the following data :-
    Ship_date
    01/10/2010
    07/02/2011
    15/01/2011
    25/01/2011
    31/01/2011
    TBA
    STOP
    11/01/2011
    TBA
    Hence when come to sorting, I will like it to be date format like sorting so that the earlier date will display first then only follow by the character. The expected result will be :-
    ship_date
    01/10/2011
    11/01/2011
    15/01/2011
    25/01/2011
    31/01/2011
    07/02/2011
    STOP
    TBA
    Trying to do the normal sorting, it does not exactly sort on the date format, as it only sort on the first two character on the date hence I am not getting the correct sorting on this.
    01/10/2011
    07/02/2011
    11/01/2011
    15/01/2011
    25/01/2011
    31/01/2011
    STOP
    TBA
    Could someone help me on this. Thanks.
    Lim

    Hi, Lim,
    sm**** wrote:
    Hi all,
    I got one character field created ( varchar2 ) for the purposed to let user the enter the date and also any character since it is a character field.That's a very bad idea. Use a DATE column for storing dates. Have another, separate column for VARCHAR2 data.
    Hence when come to sorting, I will like it to be date format like sorting so that the earlier date will display first then only follow by the character. The expected result will be :-
    If you must deal with the table as it is:
    ORDER BY  CASE
              WHEN  TRANSLATE ( ship_date
                        , '012345678'
                        , '999999999'
                        ) = '99/99/9999'
              THEN  SUBSTR (ship_date, 7)
                 || SUBSTR (ship_date, 4, 2)
           END
    ,       ship_dateThe CASE expressionj sorts anything the looks like a date ('99/99/9999' where '9' stands for any digit) first, in order by the last 4 digits, then the middle 2 digits. The first 2 digits are sorted by the second ORDER BY expression.
    I will like it to be date format like sorting so that the earlier date will display first then only follow by the character. The expected result will be :-
    ship_date
    01/10/2011
    11/01/2011
    15/01/2011
    25/01/2011
    31/01/2011
    07/02/2011That must be a mistake. I don't believe you want January to come after October and before February, but if you do, you can change what comes after THEN in the CASE expression.

  • Jump from alv report to qa03 screen based on PRUEFLOS field

    Hi experts,
    I developed one alv report ,in that one field name is PRUEFLOS (inspection lot number).I want to jump from alv report
    to QA03 screen based on PRUEFLOS field.I wrote in this way but i didn't get.
    FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
      CASE SELFIELD-FIELDNAME.
        WHEN 'PRUEFLOS'.
          READ TABLE T_FINAL INDEX SELFIELD-TABINDEX.
          SET PARAMETER ID  'QLS' FIELD T_FINAL-PRUEFLOS.
          CALL TRANSACTION 'QA03'   AND SKIP FIRST SCREEN.
      ENDCASE.
    ENDFORM.
    what is the problem ?pls help me in this.

    Hi Ram,
    Recheck:
    1) You have passed 'FORM USER_COMMAND' in 'I_CALLBACK_USER_COMMAND' while calling f.m. for ALV displa, and
    2) You have checked the value of user command, i.e.
    FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
    CASE SY-UCOMM.
    WHEN '&IC1'.
    CASE SELFIELD-FIELDNAME.
    WHEN 'PRUEFLOS'.
    READ TABLE T_FINAL INDEX SELFIELD-TABINDEX.
    SET PARAMETER ID 'QLS' FIELD T_FINAL-PRUEFLOS.
    CALL TRANSACTION 'QA03' AND SKIP FIRST SCREEN.
    ENDCASE.
    ENDCASE.
    ENDFORM.
    Regards,
    Birendra

  • How to creat a Data provider  based on different fields in SAP BW ?

    Hi,
    Experts,
    There are  20 fields  of  Plant Maintainace  like : 
    SWERK
    BEBER
    STORT
    TPLNR
    EQUNR
    INGRP
    QMDAT   ---peroid
    STTXT
    QMDAT  - Date of Notification
    QMNUM
    QMTXT
    QMART
    AUSVN
    AUZTV
    AUSBS
    AUZTB
    AUSZT
    ERNAM
    QMDAB
    AUFNR
    I  want to creat a  Report based upon these fields  ?
    For that I h'v  checked the relevant Fields to the   existing standard  Datasource  in Bw side   &
    Checked  cubes   created  based upon these Datasource  in Bw side !
    i h'v found  some fields are  existing different cubes & some are  missing .
    How to creat a Data provider  based on different fields in SAP BW ?
    plz suggest      !!!!!!!
    Thanx,
    Asit
    Edited by: ASIT_SAP on Jul 15, 2011 6:25 AM
    Edited by: ASIT_SAP on Jul 15, 2011 6:27 AM
    Edited by: ASIT_SAP on Jul 15, 2011 12:37 PM

    Hi Lee, Please see below..
    DECLARE @Machine2 TABLE
    DispatchDate DATE
    INSERT INTO @Machine2 VALUES ('2014/02/01'), ('2014/02/02'), ('2014/02/03')
    DECLARE @DateFrom DATE
    SELECT @DateFrom = DATEADD(D,1,MAX(DispatchDate)) FROM @Machine2
    SELECT @DateFrom AS DateFrom
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • How to move the value from a character field to numeric or packed decimal

    Hi,
    can anyone explain me on how to move the value from a character field to numeric or packed decimal.
    Please help me on this. Thanks...
    Regards,
    Rose.

    Hi ,
    if you use keyword MOVE u may loose the decimal and thoussan separator and if u don't want to loose them just call the FM ..HRCM_STRING_AMOUNT_CONVERT.
    i doubt wherther it is HRCM or HCRM just try using *
    this will suit ur requirement.
    Regards,
    KK

  • How to find the list of  transaction code based on a  field ?

    Hi  Gurus
    I have a unique requirement.We are adding a  new field into our system and want to know which all t-code  contains that field ?  So that we can update the  user training manual. Can some one tell me the ways and means of  finding the list of all the t-code ( or where used e.g functional area ) based on  " a field" ?
    Thanks in advance
    SN

    Hi,
    1. Tcode KS02.
    2. click on the text "Cost Center"
    3. hit F1
    4. Click on the technical information
    5. in the next screen double click on Field name :KOSTL
    6. Select the row for the component KOSTL
    7. Click on the display list
    8. In the next screen, in the object name:KBAS
    Drilldown to transactions.
    Here you get a complete list of the transactions.
    Hope its useful.
    thanks.

  • PM Notification - Hide fields based on other field's value

    Hello experts,
    I am looking for an user exit which allows me to hide some fields based on other field's value.
    For example, I have field 1 and field 2. When I open my notification, if the value of field 2 is 'aaa', field 1 has to be hidden.
    There should be an user exit but I can't find it...
    Thanks for your help!

    Hi everyone,
    Any thoughts? any help is appreciated...
    Thanks

Maybe you are looking for

  • Vendor Text must be copied into PO texts.

    Hi Experts I assume that both "Purchasing Memo" and "Purchase Order Text" should be copied from the vendor master. When testing, only the "Purchase Order Text" is getting copied into the Purchase order. However i want the purchasing memo to also appe

  • Adobe Reader 11.7.1 on Android and using "Search" on a  76.0Mb file.

    Is it possible to find the "next" occurrence and maybe do a repeat find,  instead of finding ALL occurrences?  In a file that's 76Mb, finding all occurrences of the digits 855 digits took 4 minutes 45 seconds  minutes to find 18 occurrences.  ( Galax

  • Epson RX-700 cant use Epson print CD function .....

    Since i upgrade from MAC OS X 10.4.10 to 10.5 i can print page as usual but the Epson Print CD do not work and give me a message ; cant find the drivers for the application. What i can do ..... please Help.

  • ACTION_UPDATE of tables with 32 columns

    Is anyone else having this problem: SQLEXCEPTION SQL command not ended properly. I have a model of a single table with more than 32 columns. I get this error whenever I use the WebActionCommand ACTION_UPDATE. But only on this table.

  • Problem with Mail in Leopard

    After installing Leopard (Not Upgrade) and sync all my information back from .MAC. My Mail seems to has some problem. There are no emails listed when I click on Inbox or Junk but when I click directly to the mailboxes all email appeared. I have 6 to