here goes my first question:

I have to replace the tag :

DECLARE @PageUrl varchar(200)
DECLARE @Body varchar(MAX)

SET @PageUrl = 'http://www.website.com/site1/site2/pageName.asxp?rid=1232'
SET @Body = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus, 
{URL} enim nec posuere volutpat, neque dui volutpat turpis. '

SET @Body = REPLACE(@Body,'{Url}', CONVERT(varchar,@PageUrl))
PRINT @Body

My expected outcome is:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus,
http://www.website.com/site1/site2/pageName.asxp?rid=1232 enim nec posuere volutpat, neque dui volutpat turpis.

And also the print outcome is:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus,
http://www.website.com/site1/s enim nec posuere volutpat, neque dui volutpat turpis.

As you can tell the replace function cuts the url string at its 31...

What I am doing wrong?

Thanks.

The issue is not the replace method , it's the convert method..

You have to either specify the size of the converted type

SET @Body = REPLACE(@Body,'{Url}', CONVERT(varchar(200),@PageUrl))

or as it is already understood to be a varchar only use the variable..

SET @Body = REPLACE(@Body,'{Url}', @PageUrl)

Should you take a look in the char/vachrar page

When n isn't specified by an information definition or variable declaration statement, the default length is 1. When n isn't specified while using the CAST and CONVERT functions, the default length is 30.

It's getting stop only at that line:

SET @Body = REPLACE(@Body,'{Url}', CONVERT(varchar,@PageUrl)) 

Make use of this:

SET @Body = REPLACE(@Body,'{Url}', CONVERT(varchar(200),@PageUrl)) 

You do not specify a varchar length:

CONVERT(varchar,@PageUrl)

you know what the default is? 30, exactly like you say within the question (the 31st char towards the finish is missing)

utilize it such as this:

CONVERT(varchar(200),@PageUrl)

to obtain all of the figures