High Plains Grifter (9/24/2012)
Ok... Magic? I guess that one needs a google; I cannot explain that by looking!
There's a good explanation in BOL - the output datatype of REPLICATE depends upon the input datatype. Casting outside of REPLICATE is too late.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden