SQL: replace a string with another string

By mortl92 on Apr 24, 2013

This stored sql procedure is used to replace a special character (or string) of your field with another string.
See:http://wiki.coolorange.com/index.php?title=documentAnalyzer/5._Migration_PSP_to_Vault/Tips_&_Tricks for more details about the usage.

You can call the procedure like this:
DECLARE @return_value int, @value nvarchar(2000)
EXEC @return_value = [dbo].[cOReplaceFieldValue]
@value = @value OUTPUT,
@fieldValue = N'hallo/hallo',
@toReplace = N'/',
@replaceWith = N'
SELECT @value as N'@value'

This will output this: 'hallo_hallo'

CREATE PROCEDURE [dbo].[cO_ReplaceFieldValue] (@value NVARCHAR(2000) OUTPUT, @fieldValue varchar(200),@toReplace varchar(200),@replaceWith varchar(200))
  SET @value = null
  select @value = ISNULL(REPLACE(@fieldValue, @toReplace, @replaceWith), '')


Sign in to comment.
Hawkee   -  Apr 24, 2013

Interesting. What practical uses does this have?

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.