Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4538548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:49:35+00:00 2026-05-21T14:49:35+00:00

I have a scenario where I need to convert rows to columns. I likely

  • 0

I have a scenario where I need to convert rows to columns. I likely need to use PIVOT, but I haven’t been able to figure this one out.

Here is a simplified version of what I have:
Table: ContentAuthor

ContentID | AuthorName
----------------------
1         | Joe
1         | John
1         | Mary
2         | John
2         | Dan
3         | Sam

What I would like to get:

ContentID | Author1  | Author2  | Author3  | Author4  | Author5
-----------------------------------------------------------------
1         | Joe      | John     | Mary     |          |
2         | John     | Dan      |          |          |
3         | Sam      |          |          |          |

At this point I’m not really concerned with the order they show up.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:49:36+00:00Added an answer on May 21, 2026 at 2:49 pm

    This will work for up to 5 authors per ContentId if you need to allow for arbitrary amounts then you will need to use dynamic SQL

    ;WITH ContentAuthor(ContentID, AuthorName) AS
    (
    SELECT 1,'Joe' UNION ALL
    SELECT 1,'John' UNION ALL
    SELECT 1,'Mary' UNION ALL
    SELECT 2,'John' UNION ALL
    SELECT 2,'Dan' UNION ALL
    SELECT 3,'Sam'
    ),T AS
    (
     SELECT *,
            ROW_NUMBER() OVER (PARTITION BY ContentID ORDER BY (SELECT 0)) RN
     FROM ContentAuthor
    )
    SELECT ContentID,
           [1] AS Author1,
           [2] AS Author2,
           [3] AS Author3,
           [4] AS Author4,
           [5] AS Author5
    FROM T
    PIVOT(MAX(AuthorName) FOR RN IN ([1],[2],[3],[4],[5])) AS Pvt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario where I need to convert columns of table to rows
I have this scenario where I need data integrity in the physical database. For
I have a scenario in oracle where i need to be able to reuse
I have a scenario where I need to use javascript to call a action
Hi I have a scenario where I need to convert the default Charset should
Have a scenario where i need to compile my project with jdk 1.5 but
I have a scenario where I need to upload a file from one web
I have a scenario where I need to do the following in a transaction:
I have a scenario where I need to search from many binary files (using
I have a scenario where I need a desktop console app to communicate with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.