• 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.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2