From: Hugo Kornelis on
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
>with 'dogs'.
(snip)
>I would much rather make a little table that had the variables and
>their values:
(snip)
>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.

Hi Bill,

If it's just the one phrase (in a variable), then this works on my
database:

SELECT @phrase_tx = REPLACE(@phrase_tx, variable_nm, variable_value_tx)
FROM phrase_variable
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