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

  • Home
  • SEARCH
  • 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 8159317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:52:02+00:00 2026-06-06T17:52:02+00:00

Imagine I have this table: Column A | Column B | Column C ——————————

  • 0

Imagine I have this table:

Column A | Column B | Column C
------------------------------
   111         X        10
   111         Y        12

How can I query this table to show the results like these:

Column A |     X     |      Y
-----------------------------------
   111         10           12
  • 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-06-06T17:52:04+00:00Added an answer on June 6, 2026 at 5:52 pm

    You can perform this via a PIVOT. You can use either a static PIVOT where you know the number of columns that you want to rotate or you can use a dynamic PIVOT

    Static Pivot (see SQL Fiddle with Demo)

    SELECT *
    FROM 
    (
      select *
      from t1
    ) x
    pivot
    (
      min(columnc)
      for columnb in ([X], [Y])
    ) p
    

    Dynamic Pivot (see SQL Fiddle with Demo)

    DECLARE @cols AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX);
    
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(columnb) 
                        from t1
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)') 
            ,1,1,'')
    
    set @query = 'SELECT columna, ' + @cols + ' from 
                 (
                    select *
                    from t1
                ) x
                pivot 
                (
                    min(ColumnC)
                    for ColumnB in (' + @cols + ')
                ) p '
    
    execute(@query)
    

    Both versions will give the same results. The second works when you have an unknown number of columns that will be transformed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

imagine I have this table called Department. Each Department can have child Departments. I
Imagine I have a document like this: post = {title: a, comments: [{hour: 08:00,
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
i need a timer that works like this : imagine somebody have a limit
Imagine that I have a Customer table. And in this table is an ID
I have a table in SQL Server 2008 that looks kind of like this:
Lets say I have a session table like this: [Session] ------- Id: int UserId:
I have a table that has a view_count column. I would like to increment
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]

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.