Results 1 to 2 of 2

Thread: SQL Server Replace Function

  1. #1
    Expert Member
    Join Date
    Sep 2005
    Answers
    206

    SQL Server Replace Function

    Hello, i am looking for sql server equivalent function for this ...

    Could some one help me ...

    PHP Code:
    function removealphas (byval alphanum as variant
    dim clean as string dim posa_charpos 

    if isnull(alphanumthen 
    exit function f
    or pos 1 to len(alphanum
    a_char$ = mid(alphanumpos1
    if 
    a_char$ >= "0" and a_char$ <= "9" 
    then clean$ = clean$ + a_char
    end if 
    next 
    pos removealphas 
    clean
    end function 
    thanks, suji


  2. #2
    Contributing Member
    Join Date
    Jun 2006
    Answers
    95

    Re: SQL Server Replace Function

    CREATE FUNCTION dbo.REMOVEALPHA
    (@str VARCHAR(8000))
    RETURNS VARCHAR(8000)

    BEGIN
    declare @validchars varchar(8000)
    set @validchars = '0-9'
    WHILE PATINDEX('%[^' + @validchars + ']%',@str) > 0
    SET @str=REPLACE(@str, SUBSTRING(@str ,PATINDEX('%[^'
    + @validchars +']%',@str), 1) ,'')
    RETURN @str
    END
    GO



    Execuete:
    SELECT dbo.REMOVEALPHA('REPLACEAPHA1111122')


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact