Sean Lange (11/25/2015)
lnardozi 61862 (11/25/2015)
In the script, you're selecting into a variable. No matter how many rows there are, the variable only gets set once.Not quite, the OP is using a concatenation trick that will keep injection each row into the variable. I use that technique myself and it works just fine.
Here is a very simplified example of what the OP is doing.
declare @TableNames varchar(max) = ''
select @TableNames = @TableNames + name + ','
from sys.tables
select @TableNames
It works fine until you find out that the set is not ordered. It suffers from the same problems as the quirky update. That's why I prefer the FOR XML PATH('')[/url] option.