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 7890785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:26:48+00:00 2026-06-03T06:26:48+00:00

I think that PIVOT will help me accomplish this, but I can’t get anything

  • 0

I think that PIVOT will help me accomplish this, but I can’t get anything started. I am having serious SQL brain farts today, I need some help.

Here is the output I have now:

Id    Name  Question    Answer
0     Test  Vault       A
0     Test  Container   1
1     Foo   Vault       B
1     Foo   Container   2

And this is my desired output:

Id   Name Vault Container
0    Test A    1
1    Foo  B    2

Can this be done?

If that is impossible or terribly complex to do, I have an alternate way to approach this. The output for my alternate query is:

Id   Name VaultId ContainerId
0    Test A       NULL
0    Test NULL       1
1    Foo  B       NULL  
1    Foo  NULL       2

And here I need to be able to suppress it into one row per Id/Name. I can’t remember how to do either of these!

  • 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-03T06:26:49+00:00Added an answer on June 3, 2026 at 6:26 am
    DECLARE @Test TABLE
    (
         Id      INT 
        ,[Name]VARCHAR(10) NOT NULL
        ,Question       VARCHAR(10) NOT NULL,
        Answer VARCHAR(10)
    
    );  
    INSERT  @Test   VALUES (0,'test1', 'vault','a');
    INSERT  @Test   VALUES (0,'test1', 'Container ','1');
    INSERT  @Test   VALUES (1,'test4', 'vault','b');
    INSERT  @Test   VALUES (1,'test4', 'Container','2');
    
    
    
    ;WITH CTE
    AS
    (
        SELECT  t.id, t.[Name], t.[Question    ]   ,t.Answer
         FROM    @Test t
    )
    
    SELECT  * 
    FROM    CTE
     PIVOT   ( max(answer) FOR Question     IN (vault,container) )  f;
    

    enter image description here

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

Sidebar

Related Questions

I think that some newer languages like JS can do this natively, but I
I think that this problem can be sorted using reflection (a technology which I'm
I don't think that this could be done in C#, but posting this just
I think that asking this might be kind of silly but I'm still wondering
I think that's what clip are used for but I can't find any example
I think that I am having a slow evening but I have a question
I can't seem to get my head around this problem where I think I
I haven't seen this addressed yet, but I think that might be because I
I am currently coding an application that involves navigating between pivot control. There will
I've never used a SQL Pivot, but I think now's my chance. Problem is,

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.