Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    328

    Unanswered: Removing characters

    I want to remove all non-letter, non-number characters in a string. An example string would be: How#can*I^make this@work?
    I would like it to look like HowcanImakethiswork
    I need to do this for a whole field. Any ideas?
    Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Create a user-defined function such as this:

    create function CharOnly(@TargetString varchar(500))
    returns varchar(500)
    as
    begin
    declare @NewString varchar(50)
    declare @Counter int
    set @NewString = ''
    set @Counter = 0
    while @Counter < len(@TargetString)
    begin
    set @Counter = @Counter + 1
    if ASCII(UPPER(substring(@TargetString, @Counter, 1))) between 65 and 90 set @NewString = @NewString + substring(@TargetString, @Counter, 1)
    end
    return @NewString
    end

    Then use it in your select statement like this:
    select dbo.CharOnly('How#can*I^make this@work?')

    blindman

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    If you are looking for a way to process regular expressions, click on the following link:

    link

Posting Permissions

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