Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: SQL - sepeartors

    Is there anyway of splitting a field? For example, say a field contained the string 'abc-def', is there a way of using the hyphen as a separator to return two different fields, 'abc' & 'def'

    Thanks

  2. #2
    Join Date
    Oct 2003
    Posts
    13
    declare @col char(25)
    select @col='abc-def'

    select substring(@col,1,charindex('-',@col)-1), substring(@col,charindex('-',@col)+1,char_length(@col)-charindex('-',@col))

    Replace @col with the actual column name.

Posting Permissions

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