Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 6 of 6

Thread: between characters

  1. #1
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default between characters

    I have written a line to a field that I need to separate out now using sql. The value would be something like "ID:100004 23ksdflk". I need to pull just the 100004 value for part of my query. Any ideas?

  2. #2
    AspDotNetStorefront Staff - Scott's Avatar
    AspDotNetStorefront Staff - Scott is offline Administrator
    Join Date
    Mar 2007
    Location
    Ashland, OR
    Posts
    2,390

  3. #3
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    I am trying to create a sproc to do this.

  4. #4
    esedirect is offline Senior Member
    Join Date
    Feb 2010
    Location
    Norfolk, UK
    Posts
    343

    Default

    What's wrong with SUBSTRING?

    SELECT SUBSTRING(fieldname,4,6) FROM tablename
    http://www.esedirect.co.uk
    --------------------------------------------------------------------------
    Using MS 9.2.0.0 with the following customisations:

    Lightbox/Fancybox enlarged images;
    Auto-suggest searchbox;
    Extra product information shown only to our IP Address (such as supplier info, costs, etc.);
    Failed transactions emailed via trigger;
    Custom app to show basket contents when customer online;
    Orders pushed through to accounting systems.

    All the above without source!

  5. #5
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    There are a few 'string.split' sprocs published here:

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

  6. #6
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    I ended up using the following:

    Code:
    LEFT(SUBSTRING(col, nullif(PATINDEX('%ID:[^ ]% %', col),0)+3, LEN(col)),6) AS ORDER_NUM,
    This finds "ID:" and takes the 6 numbers to the right of it.