I got a syntax error from the text on the second example.
Change the line
SELECT @mStrColumns = COALESCE(@mStrColumns + ', ', '') + '[' + CAST(SC.[NAME] AS VARCHAR(100) ) +']' ,@mStrTable = schema_Name(schema_id) + '.'TABLE_NAME'
To:
SELECT @mStrColumns = COALESCE(@mStrColumns + ', ', '') + '[' + CAST(SC.[NAME] AS VARCHAR(100) ) +']' ,@mStrTable = schema_Name(schema_id) + '.' + @mStrTable
Tom in Sacramento - For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/