How to create a function in SQL Server

前端 未结 5 1213
遇见更好的自我
遇见更好的自我 2020-12-07 18:09

Please help me, how to filter words in SQL using a function?

I\'m having a hard time if I explain it so I\'m giving example:

ID       |       Websit         


        
5条回答
  •  孤城傲影
    2020-12-07 18:57

    You can use stuff in place of replace for avoiding the bug that Hamlet Hakobyan has mentioned

    CREATE FUNCTION dbo.StripWWWandCom (@input VARCHAR(250)) 
    RETURNS VARCHAR(250) 
    AS BEGIN
       DECLARE @Work VARCHAR(250)
       SET @Work = @Input
    
       --SET @Work = REPLACE(@Work, 'www.', '')
       SET @Work = Stuff(@Work,1,4, '')
       SET @Work = REPLACE(@Work, '.com', '')
    
       RETURN @work 
    END
    

提交回复
热议问题