Check my query

  • I have the following

    DECLARE @NocMsg VARCHAR(MAX) = '';

    SELECT @NocMsg += ISNULL(TD.RefNum + ' ', '')

    FROM MyTable TD;

    This should give me a list of RefNum values separated by spaces. It worked for my test but I wanted to know if I am missing something.

    Is there a better way to do this?

    Thank you,

  • That will work to get a single value. If you need several values/groups, you could read about it in the following article:

    http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    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
  • Thanks!

    Only one value is expected.

    I was reviewing a developers code that had a cursor and thought my way would be better.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply