Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    Montreal, Canada
    Posts
    151

    Unanswered: Looping and triming records. Need help!

    Hello guys having trouble figuring this one out.

    I have a table with a columns that looks like this:

    Name
    ----------
    JohnDoe.abc.mtl
    helenDoe.abc.que
    patDoe.rdn

    Now what i want to do his loop trought record by record removing everything in front of the first coma "coma included" so ex.

    JohnDoe.abc.mtl --> JohnDoe
    helenDoe.abc.que --> helenDoe
    patDoe.rdn --> patDoe

    and then ad something in front like the word Apple\

    so ex.
    Apple\JohnDoe
    Apple\helenDoe
    Apple\patDoe

    Your help would be greatly appreciated.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Code:
    create table #temp (col1 varchar(20))
    
    insert into #temp values ('JohnDoe.abc.mtl')
    insert into #temp values ('helenDoe.abc.que')
    insert into #temp values ('patDoe.rdn')
    insert into #temp values ('JaneDoe')
    select 'APPLE\' + case when charindex('.', col1) > 0 then substring (col1, 1, charindex('.', col1) -1 ) 
    	else col1 end
    from #temp

  3. #3
    Join Date
    Jan 2004
    Location
    Montreal, Canada
    Posts
    151
    Thanks this helped alot...how do i update another column in your case statement ? if i whanted to do that base on that critiria

Posting Permissions

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