Convert ColumnValues to a row.

  • Query:

    -------

    SELECT RoleName FROM ROLES

    Output:

    --------

    RoleName

    ---------

    Admin

    User

    Process Query:

    ---------------

    DECLARE @Roles VARCHAR(100)

    SET @Roles=''

    SELECT @Roles=@Roles+','''+RoleName+''' '''+ RoleName+''' ' FROM Roles

    Print @Roles

    SET @Roles=STUFF(@Roles,1,1,'')

    Print @Roles

    EXEC ('Select ' + @Roles)

    Output:

    --------

    Admin User (Column Names)

    -------------

    Admin User (data in the form of row)

  • What is your question?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

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

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