Computed column by stripping leading text

Posted on 2012-09-22
Last Modified: 2012-09-30
I have column name ORDER which has entries like:

ABC Order Number 2120
ABC Order Number 22

I want to have computed column ORDER2 where I want to have results from column ORDER as:


In other words "ABC Order Number" need to strip which is always constant leading text.

Please advise what formula I create in my computed colum to achieve?


I am using SQL 2005 server.

Question by:NickHoward
    1 Comment
    LVL 2

    Accepted Solution

    1) Use LTRIM(RTRIM(ORDER)) to remove any leading ,trailing spaces
    2) LEN(LTRIM(RTRIM(ORDER)) ) provides you with string length
    3) Constant leading text is always "ABC Order Number" ,whose length is 16 including 2 spaces
    4) SELECT  SUBSTRING(LTRIM(RTRIM(ORDER)),17,LEN(LTRIM(RTRIM(ORDER)) )) AS ORDER2 should provide you trailing strings 2120 ,22 etc
    5) You may want to converst them into Numeric values

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now