T-SQL provides another function similar to
REPLACE(). It is
TRANSLATE(), and it looks like this:
TRANSLATE(StringToSearch, OldCharacters, NewCharacters)
This function searches
StringToSearch, which can be an actual string or a field in the database, for the characters in
OldCharacters. When it finds them, it replaces them with the corresponding characters in the
NewCharacters. Here's how it looks in action:
TRANSLATE(Text, N' .', N'*!') AS Translation
This will change the text of the slogans in the
Slogan table. The characters we're replacing are
N' .': spaces and periods. We want to translate them to
N'*!': all spaces are changed into asterisks and all dots are changed into exclamation marks. Look at the result:
||Feel the difference. Feel the powder.
||Get enthusiastic - even without alcohol.
||Each traveller's choice.