Prev: indexes and constraints
Next: String Manipulation: REPLACE multiple variables at once through a Join: How to
From: Hugo Kornelis on 18 Dec 2009 05:14
On Thu, 17 Dec 2009 17:32:12 -0800 (PST), bill wrote:
>I want to convert this sample string:
>"Some like <X> better than <Y>. I like <Y> better
>than <X>, but my daughter prefers <X>."
>To this one:
>"Some like cats better than dogs. I like dogs better
>than cats, but my daughter prefers cats."
>Thus, <X> gets replaced with 'cats' and <Y> gets replaced
>I would much rather make a little table that had the variables and
>Then, I would like to issue a statement that joins the phrase to the
>substitution tables and does the REPLACES for all variables without
>requiring lots of nesting.
If it's just the one phrase (in a variable), then this works on my
SELECT @phrase_tx = REPLACE(@phrase_tx, variable_nm, variable_value_tx)
OPTION (MAXDOP 1);
I'm not 100% sure if this is fully documented and supported though.
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis