Concatenation

  • i have a column abc_col1 in table A

    when i do a ("Select abc_col1 from A")

    i get the results as

    'SHT234'

    'SHT56'

    'SHT7980'

    i need to get the above result as

    't234'

    't56'

    't7980'

    Please advice

    thanks

  • Never mind i just got it worked

  • Glad I could help!! 🙂

    Perhaps you could post your solution? One reason is so others can search for your issue and find a solution. The other is that your solution could be made even better. No downside, other than a few minutes of your time.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • A couple techniques:

    SELECT RIGHT(abc_col1,len(abc_col1)-2)

    FROM tableA

    SELECT REPLACE(abc_col1,'SH','')

    FROM tableA

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Use length and then substring funtionc

  • iamsql1 (7/26/2013)


    Use length and then substring funtionc

    It's easy to get to the moon. All you need to do is build a rocket ship. 😉

    How would YOU use what you suggested to accomplish the task? Some code would be a big help.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (7/27/2013)


    iamsql1 (7/26/2013)


    Use length and then substring funtionc

    It's easy to get to the moon. All you need to do is build a rocket ship. 😉

    How would YOU use what you suggested to accomplish the task? Some code would be a big help.

    SUBSTRING(column, 3, len(column));

    Use Column name in first and last place of argument.

  • iamsql1 (7/27/2013)


    Jeff Moden (7/27/2013)


    iamsql1 (7/26/2013)


    Use length and then substring funtionc

    It's easy to get to the moon. All you need to do is build a rocket ship. 😉

    How would YOU use what you suggested to accomplish the task? Some code would be a big help.

    SUBSTRING(column, 3, len(column));

    Use Column name in first and last place of argument.

    That'll work. Thanks for posting it.

    As a bit of a sidebar, you can avoid the extra calculation of LEN depending on what you intend to do with the result.

    SUBSTRING(column,3,8000)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • koolme_85 (7/23/2013)


    Never mind i just got it worked

    Very cool. What did you do to fix it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply