User Profile

Collapse

Profile Sidebar

Collapse
hairlessOrphan
hairlessOrphan
Last Activity: Nov 3 '06, 06:05 PM
Joined: Nov 3 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Well, I gave it a shot. I don't know if there's a better solution than this; if you can think of one, please post!

    Code:
    CREATE FUNCTION ReplaceFirst (@origStr varchar(8000), @searchFor varchar(8000), @replaceWith varchar(8000)) 
    RETURNS varchar(8000) AS  
    BEGIN 
    	DECLARE @start AS int
    	DECLARE @end AS int
    	DECLARE @newStr AS varchar(8000)
    
    	SET @start = CHARINDEX(@searchFor, @origStr)
    ...
    See more | Go to post

    Leave a comment:


  • hairlessOrphan
    started a topic MSSQL Replace() for first occurance?

    MSSQL Replace() for first occurance?

    Hi!

    Is there any way to get the Replace() function in MSSQL to replace only the first occurence of a substring? For example, my Name column has the following data:

    Bob
    BobBob

    And I want to replace "Bob" with "Robert," but *only* the first occurence:

    Robert
    RobertBob

    Unfortunately, the length of the original string, the searchFor substring,...
    See more | Go to post
No activity results to display
Show More
Working...