Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Location
    Nottinghamshire, UK
    Posts
    364

    Unanswered: Convert MSSQL TSQL to a Formula

    Hi Folks

    First time I've posted in the Excel section, I normally float around in the SQL Server Section.

    I have a TSQL Statement that returns an Insurance Policy Number in a Business Format from a Database SQL Format and wonder if anyone could tell me how I could do the same thing in an Excel Formula.

    The System Policys are represented as a String made up of three sections

    1-5 numbers (1 to 19,999)
    A Character a-z (A to Z)
    1-2 numbers (0 to 99)

    in that Order

    I would like to flip the cell value with a formula into

    1-2 numbers (0 to 99)
    A Character a-z (A to Z)
    1-5 numbers (1 to 19,999)

    The TSQL I use to do this is:-

    Code:
     
    SET @PatInd = PATINDEX('%[a-z]%',@InPolicy)
    SELECT SUBSTRING(@InPolicy,@PatInd +1,LEN(@InPolicy)- @PatInd)
    +
    SUBSTRING(@InPolicy,@PatInd,1)
    +
    LEFT(@InPolicy,@PatInd -1)

    where PatIndex is TSQL for returning the integer position of a charcter within a String

    examples Policys are
    Code:
     
    System Business
    501A80 80A501
    1000G80 80G1000
    10001K80 80K10001
    10000K80 80K10000


    Any help muchly appreciated

    GW
    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

  2. #2
    Join Date
    Jan 2003
    Location
    Nottinghamshire, UK
    Posts
    364
    Mmmmm 25 Views and no takers?

    Is this a difficult one ?
    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    No equivalent to PATINDEX in Excel. You'll probably have to create a UDF in VBA and loop through the characters, testing (for example) the ASCII value until you find the first alpha character.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •