SEPARATE WTH HYPHEN TO STRING

  • HI ALL

    I HAVE STRING SUPPOSE

    STRING :-

    AD675498IJU76

    I WANT TO SEPARATE WITH HYPHEN (-)

    BUT EVERY TIME POSITION IS NOT FIX.

    ASSUME FIRST TIME POSITION IS :- 4

    THEN RESULT : -

    AD67-5498IJU76

    ASSUME NEXT TIME POSITION IS :- 4,6

    THEN RESULT : -

    AD67-54-98IJU76

    ASSUME NEXT TIME POSITION IS :- 4,7

    THEN RESULT : -

    AD67-549-8IJU76

    I WANT TO DYANAMIC QUERY FOR SOLVE THIS PROBLEM

    THANKS IN ADVANCE.

  • The Stuff() function can take a variable as the position.

    For example:

    declare @Position int = 2;

    select stuff('mystring', 2, 0, '-');

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (8/6/2012)


    The Stuff() function can take a variable as the position.

    For example:

    declare @Position int = 2;

    select stuff('mystring', 2, 0, '-');

    Where are you using the variable? 🙂 I think you meant this:

    declare @Position int = 2;

    select stuff('mystring',@Position, 0, '-');

    Jared
    CE - Microsoft

  • SQLKnowItAll (8/6/2012)


    GSquared (8/6/2012)


    The Stuff() function can take a variable as the position.

    For example:

    declare @Position int = 2;

    select stuff('mystring', 2, 0, '-');

    Where are you using the variable? 🙂 I think you meant this:

    declare @Position int = 2;

    select stuff('mystring',@Position, 0, '-');

    Yep. That's what happens when I post too early in the AM. Sorry about that.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 4 posts - 1 through 3 (of 3 total)

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