Results 1 to 2 of 2

Thread: Trim to space

  1. #1
    Join Date
    Oct 2005
    Posts
    58

    Unanswered: Trim to space

    What is the best way to trim a string to the space in a select statement? An example string would be:
    'asdf and hjkl'

    The result would be:
    'asdf'

  2. #2
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by asahi
    What is the best way to trim a string to the space in a select statement? An example string would be:
    'asdf and hjkl'

    The result would be:
    'asdf'
    I think you are looking for a combination of substring and charindex. As in:

    DECLARE @MyString varchar(255)
    SELECT @MyString = 'asdf and hjkl'

    SELECT Substring (@MyString, 1, CHARINDEX (' ', @MyString) - 1)

    Regards,

    hmscott
    Have you hugged your backup today?

Posting Permissions

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