SQL Server Performance

Split Column Data

Discussion in 'General Developer Questions' started by keleparker, Jul 20, 2003.

  1. keleparker New Member

    NT User NorthWindob smith logged on to Parker, Kelly mailbox, and is not the primary Windows NT account on this mailbox. <br /><br />And from this you wanted to split this field up and get the following information from it:<br /><br />1. Northwindob smith<br />2. loggon on to Parker, Kelly mailbox<br />3. not the primary Windows NT<br /><br />How could I do it?<br /><br />[<img src='/community/emoticons/emotion-6.gif' alt=':(' />]
  2. rushmada New Member

    U can use the following query to acheive the output.

    declare @t1 varchar(2000)
    set @t1='NT User NorthWindob smith logged on to Parker, Kelly mailbox, and is not the primary Windows NT'
    select ltrim(rtrim(substring(@t1,1,charindex(' logged',@t1)))),
    ltrim(rtrim(substring(@t1,charindex(' logged',@t1),(charindex(', and',@t1)-charindex(' logged',@t1))))),ltrim(rtrim(substring(@t1,charindex('not',@t1),len(@t1))))




    Rushendra

Share This Page