How to sort the alpha numeric character into number?

Hi Good day!
I have here a sample data as shown below that needs string manipulation to sort the metric sizes numerically.
Select MetricSize From Sizes Order By MetricSize; which yields the following result:
10 x 5.5 x 2
125 x 95 x 13.5/21
1264.01 x 1200 x 22.23
130 x 105 x 12
210 x 180 x 15
28 x 16 x 15.2
28 x 16.8 x 6/7.5
52 x 25 x 10
52 x 25 x 7/7.5
52/58 x 25 x 7
52/59 x 25 x 10/15.5
55/61 x 35 x 11.5/16
74.2/78.2 x 56 x 8/10.5
74.5/79.5 x 45/42.5 x 12/13.7
But the requirement is to sort this sizes numerically so that the output would be look like this:
10 x 5.5 x 2
28 x 16 x 15.2
28 x 16.8 x 6/7.5
52 x 25 x 7/7.5
52/58 x 25 x 7
52/59 x 25 x 10/15.5
52 x 25 x 10
55/61 x 35 x 11.5/16
74.2/78.2 x 56 x 8/10.5
74.5/79.5 x 45/42.5 x 12/13.7
125 x 95 x 13.5/21
130 x 105 x 12
210 x 180 x 15
1264.01 x 1200 x 22.23
By the way the format for these sizes is composed of Outside Length x Inside Length x Thickness. But there are some sizes that contains slash '/' which is considered as special sizes.
So one of my solution is to separate the numbers into 3 columns so that I can sort it by outside, inside length and thickness.
Select MetricSize,
Convert(Numeric(18, 2), Left(SubString(MetricSize, PatIndex('%[0-9.-]%', MetricSize), 100),PatIndex('%[^0-9.-]%',
SubString(MetricSize, PatIndex('%[0-9.-]%', MetricSize), 100) + 'X')-1)) As Outside,
Substring(MetricSize, charIndex('x', MetricSize) + 2, charIndex(reverse(Left(SubString(reverse(MetricSize),
PatIndex('%[0-9.-]%', reverse(MetricSize)), 100),
PatIndex('%[^0-9.-]%', SubString(reverse(MetricSize), PatIndex('%[0-9.-]%',
reverse(MetricSize)), 100)))), MetricSize) - 4 - charIndex('x', MetricSize)) As Inside,
Convert(Numeric(18, 2), Reverse(Left(SubString(reverse(MetricSize), PatIndex('%[0-9.-]%', reverse(MetricSize)), 100),PatIndex('%[^0-9.-]%',
SubString(reverse(MetricSize), PatIndex('%[0-9.-]%', reverse(MetricSize)), 100) + 'X')-1))) As Thickness
From Sizes Order By Outside , Inside, Thickness
It is almost there but the result is not yet the exact result that I really wanted. There's a problem if the sizes contains slash '/' especially on the middle or the last portion of the character, which give me headache for a several minutes/hours. :)
I need help for this problem. Your help will be greatly appreciated.
Thanks in advance.
Hardz

create table #t (col varchar(100))
insert into #t values ('10 x 5.5 x 2')
insert into #t values ('125 x 95 x 13.5/21')
insert into #t values ('1264.01 x 1200 x 22.23')
insert into #t values ('130 x 105 x 12')
insert into #t values ('130 x 95 x 12') --added
insert into #t values ('210 x 180 x 15')
insert into #t values ('28 x 16 x 15.2')
insert into #t values ('28 x 16.8 x 6/7.5')
insert into #t values ('52 x 25 x 10')
insert into #t values ('52 x 25 x 7/7.5')
insert into #t values ('52/58 x 25 x 7')
insert into #t values ('52/59 x 25 x 10/15.5')
insert into #t values ('55/61 x 35 x 11.5/16')
insert into #t values ('74.2/78.2 x 56 x 8/10.5')
insert into #t values ('74.5/79.5 x 45/42.5 x 12/13.')
;with mycte as (
select col,
parsename(Replace(replace(col,'.','*'),'X','.'),3) col1
,parsename(Replace(replace(col,'.','*'),'X','.'),2) col2
,parsename(Replace(replace(col,'.','*'),'X','.'),1) col3 from #t)
,mycte1 as (
Select col,
Cast(ISNULL(Replace(parsename(Replace(col1,'/','.'),2),'*','.'), Replace(parsename(Replace(col1,'/','.'),1),'*','.')) as Decimal(6,2)) col11
, Cast(Replace(parsename(Replace(col1,'/','.'),1),'*','.') as Decimal(6,2)) as col12
, Cast(ISNULL(Replace(parsename(Replace(col2,'/','.'),2),'*','.'), Replace(parsename(Replace(col2,'/','.'),1),'*','.')) as Decimal(6,2)) col21
, Cast(Replace(parsename(Replace(col2,'/','.'),1),'*','.') as Decimal(6,2)) as col22
, Cast(ISNULL(Replace(parsename(Replace(col3,'/','.'),2),'*','.'), Replace(parsename(Replace(col3,'/','.'),1),'*','.')) as Decimal(6,2)) col31
, Cast(Replace(parsename(Replace(col3,'/','.'),1),'*','.') as Decimal(6,2)) as col32
from mycte )
Select col from mycte1
Order by col11,col12,col21,col22,col31,col32
drop table #t

Similar Messages

  • Trouble sorting in alpha-numeric order

    Can someone please help me figure out why iPhoto doesn't know how to sort things alpha-numerically by title?
    For example, I am importing photos from my hard drive. Numbers go 1-200 as they should. However when I get into iphoto (set to sort by title), iphoto decides to go 1, 10, 100, 2, 20, 200, 3, 30, etc. Its very annoying since they are no longer in the right order. 1 should be next to 2, not 10. Computers have been ordering things in number order for ages, why is iPhoto so confused?
    Are there different settings that will import things properly. I know if I was using albums, I could make sure the album is set to sort "manually" prior to importing. Then they will be in their original order. I can't do that when just importing into iphoto/events as far as I know.
    Any suggestions?

    iPhoto sorts jsut fine - soem human had mis-names the photos
    "space" "space" 1 does not sort Alpha-Numerically to the same place a 001 - nor does 1 sort the same as 001
    An Alpha Numeric sort considers both Alphabetic and Numeric characters and therefore if you want the sort to match your expectiations then you need to be sure the characters you are sorting on are correct - the conmputer can not read yoru mind and see that you do not really want an alpha-numeric sort after all
    LN

  • How to generate password alpha numeric value

    dear friends,
    i have written a simple pl/sql to generate a password.
    declare
    cursor c1 is select * from passwd;
    begin
    for I in c1
    loop
    if I.pfno < 3000 then
    update passwd set pwd=I.pfno where i.pfno=pfno;
    ELSe
    update passwd set pwd=lpad(round(I.pfno/20520),4,'0') where i.pfno=pfno;
    commit;
    end if;
    end loop;
    end;
    In this the pfno is 8 digit alpha numeric. I get password generated when it is only numeric but how could i get if pfno is like 04MAS155.
    Kindly help as i have to generate the same as early as possible. I have already been given with procedure to generate random password by our guys but still as i had already generated password to some employees in my concern based on querries like above i request your help to generate for alpha numeric 8 digit number.

    -- get a random string
        FUNCTION string (opt char, len NUMBER)
              /* "opt" specifies that the returned string may contain:
                 'u','U'  :  upper case alpha characters only
                 'l','L'  :  lower case alpha characters only
                 'a','A'  :  alpha characters only (mixed case)
                 'x','X'  :  any alpha-numeric characters (upper)
                 'p','P'  :  any printable characters
            RETURN VARCHAR2;  -- string of <len> characters (max 60)
        PRAGMA restrict_references (string, WNDS);

  • How to add the library of linphone into existing project ?

    How to add the library of linphone into existing project ?

    How to add the library of linphone into existing project ?

  • How to insert the image or logo into the table as a field in webdynpro abap

    Hi Friends,
    Please tell me how to insert the image or logo into the table as a field in webdynpro abap.........

    Hi Alagappan ,
          In your view layout you take table UI element and then you bind it with some context nodes.
    The attributes of your nodes comes as a field.
    Now in these fields you can set various properties and image is one of them.
    Go to ->
    1. View Layout -> Right Click on ROOTUIELEMENTCONTAINER -> INSERT ELEMENT -> TABLE
    2. Right click on table -> Create Binding.
       Here you have to bind it with the appropriate context node.
    You will get two properties here
    a- Standard Cell Editor :- ( make it image )
    b- Standard properties :- ( If required set image properties ).
    3. If you want put image from out side then import it as a mime object and set the source of your table field ( used as a image )
    also have a look :-
    [Image Properties|http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm]
    Hope this will solve your problem.
    Reply if any case of any issue.
    Thanks & Regards,
    Monishankar C

  • How to load the data from informatica into bw & how to report the data

    Hi friends,
    how to load the data from informatica into bw & how to report the data
    using cognos.(i.e how to access the data in sap bw using cognos 8 BI suite).
    Thanks,
    madhu.

    Inorder to report BW data into Cognos you can extract data from using Open Hub to the DB table from which Cognos reads.
    For BW informatic integration refer following docs:
    http://www.aman.co.il/aman/pfd/DataInteg_BR.q103cd.pdf.pdf
    http://h71028.www7.hp.com/enterprise/cache/3889-0-0-225-121.html
    http://devnet.informatica.com/learning/ePresentations.asp
    http://72.14.203.104/search?q=cache:C741L86Q19oJ:devnet.informatica.com/showcase/resources/Essbase_DataSheet.pdfinformaticapowerconnect(BI)&hl=en&gl=in&ct=clnk&cd=3
    http://www.informatica.com/customers/utilities_energy/fpl_group.htm
    http://www.informatica.com/solutions/resource_center/technote_sapbw_65241004.pdf#search=%22Informatica%20to%20Bw%22

  • How to store the flat file data into custom table?

    Hi,
    Iam working on inbound interface.Can any one tell me how to store the flat file data into custom table?what is the procedure?
    Regards,
    Sujan

    Hie
    u can use function
    F4_FILENAME
    to pick the file from front-end or location.
    then use function
    WS_UPLOAD
    to upload into
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'   "Function to pick file
        EXPORTING
          field_name = 'p_file'     "file
        IMPORTING
          file_name  = p_file.     "file
      CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
         filename                       = p_file1
        TABLES
          data_tab                      = it_line
    *then loop at it_line splitting it into the fields of your custom table.
    loop at it_line.
              split itline at ',' into
              itab-name
              itab-surname.
    endloop.
    then u can insert the values into yo table from the itab work area.
    regards
    Isaac Prince

  • Custom Search portlet : how to sort the result in sequence (Portal 10.1.4)

    With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • How to convert the x/y pixel into Lat/Lon?

    Does anyone know how to covert the X/Y coord into Lat?lon coord system? What is the formular?
    Thanks!!!
    Ming

    Depends on the projection your map is using.

  • Custom Search Portlet : How to Sort the Result By Sequence (Portal 10.1.4)

    Customer request: With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    (Like it's possible in MyOracle)
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • How to list the JAR files loaded into the Oracle Database ?

    How to list the JAR files loaded into the Oracle Database ?

    From 11.1 onwards, the below two views are available to identify the jar files loaded into the Database.
    JAVAJAR$
    JAVAJAROBJECTS$
    By querying the JAVAJAR$ view you can know information about the JAR files loaded into the Database and using JAVAJAROBJECTS$ view you can find all the java objects associated with the given JAR file.
    These views are populated everytime you use LOADJAVA with "-jarsasdbobjects" option to load your custom java classes.
    But unfortunately this feature is available only from 11.1 onwards and there is no clear workaround for above in 10.2 or earlier.

  • How can if find the most repeated character and number ???

    Hi,
    I have a question. For instance, if we have a text file which contains:
    aaabbbhhhhhhtttttsjs12366
    How can i find the most repeated character and number. I have to add this code to the following program:
    I will aprreciate if you can help.
    Regards,
    Serkan
    import java.io.*;
    public class LineLen {
         public static void main(String args[]) throws Throwable {
              final String filename = "deneme1.txt";
              BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
              String line = infile.readLine();
              int linenum = 0;
              while (line != null) {
                   int len = line.length();
                   linenum++;
                   System.out.print(linenum + "\t");
                   for (int i = 0; i<len; i++)
                   System.out.print("*");
                   System.out.println("");
                   line = infile.readLine();
    }

    For a small alphabet like English, array migt be used:
    //in a for loop
    ++array[s.charAt(i)];For a big alphabet like chinese, HashMap might be barely used:
    map.put(s.charAt(i), increment(map.get(s.charAt(i))));
    // increment is a user defined method, possibly for an Integer object,
    // that returns a new Integer object

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • How to get the footage's current frame number in expression?

    There are 2 layers.One is text layer,one is sequence layer.
    Footage has begun from the 20th frame.
    Therefore, the number of composition's current frame number and footage's frame number has shifted.
    I want to show footage's frame number in text layer . not composition's frame number.
    How to get the footage's current frame number in expression?
    Tatsuya

    >Footage has begun from the 20th frame.
    Do you mean that the footage layer has been trimmed (so that the start of the footage lines up with the start of the comp, but the first 19 frames are not visible), or moved to the left (so that frame 20 lines up with the comp's frame 0), or that the sequence actually begins with the 20th frame (at frame 0 of the comp), or something else?
    Are the frame rates of the comp and the footage the same?
    Dan

  • How to split the IDOCS based on document number change whit out BPM

    Hi all,
    Thanks,for giving the responce..
    Scenario:File to IDoc.
    Problum1 : How to Split the IDocs based on document number change in the source file with out BPM.My file contains document numbers like
    20000092
    20000092
    20000092
    50000050
    50000050
    50000065
    I want 3 IDocs in target system.i.e 1 for 20000092,20000092,20000092
                                                       2 for 50000050,50000050
                                                       3 for 5000006
    By using external definations i am getting 6 IDOCs insted of 3.
    Problum 2:Is there any chnges/modifications in Directory when we are using external definations.
    Could u plz provide me the step by step process(Repository/Directory) with using of external definations.
    Thanks in advance.
    Regards,
    KP

    HI,
    for this no need of BPM.
    You can think of Idoc bundling concept to acheive this-just you need to do the external definition to change the idoc occurence
    /people/michal.krawczyk2/blog/2005/12/04/xi-idoc-bundling--the-trick-with-the-occurance-change
    to achieve for each document no, one idoc, you can write small user defined function in the mapping with context handling you an achieve this.
    For this e.g
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6bd6f69a-0701-0010-a88b-adbb6ee89b34
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/877c0d53-0801-0010-3bb0-e38d5ecd352c
    Regards,
    Moorthy

Maybe you are looking for

  • Batch Management Level

    Hi all, Batch management drives us difficulty, all finished goods have a batch number in our system. But cause of this our system grows fastly and process management is so difficult. We think about cancelling batch management and use serial number ma

  • About exercise 3, file missing

    Hi Some one, First i must say this video is awesome. And i am coming with it for couple days. But there is a file missing. at below day3, exercise 3 "Exercise: ColdFusion Version: Using RemoteObject to send data to the server" I couldnot locate the E

  • IMac 21.5 (2011) won't let me log in!

    Hi again, I'm having issues with my iMac lately! It starts up, log-in-screen with all users appears, so far so good. I choose a user, type in password and then BOOM! WHITE/BLANK SCREEN hits me! I still see the cursor and can move it around, but the d

  • How do i save an imovie to my dropbox

    how do i save a imovie to my dropbox?

  • PNG in Batch/Image Processor?

    Can we PLEASE have PNG-24 added to the Image Processor? I've got this basically down as it is quite similar to the way I used to process in batch back in 7.0 days. Set up an action with a save-for-web with a resize and a ctrl-alt-shift-S. Use Bridge