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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:11:24+00:00 2026-06-16T04:11:24+00:00

My problem: I have my base table that stores username, and their feedback response.

  • 0

My problem: I have my base table that stores username, and their feedback response. In the table with each user I have 2 questions and 2 responses.

ans1 ans2 are text columns where user can entry their comments against each question/answer pair.

Input table:

username    question1   question2   opt1    ans1    opt2    ans2
-----------------------------------------------------------------------
user1   ques1   ques2   a   answer1 b   answer2
user2   ques1   ques2   c   answer11    d   answer21

I want my output (for the given input as above table)query should produce a result in below format:

Username    Question    Option  Comment
----------------------------------------------------
user1   ques1   a   answer1
user1   ques2   b   answer2
user2   ques1   c   answer11
user2   ques2   d   answer21

I tried this query to get the result but it is somehow taking all possible combinations..pls suggest..

SELECT Username,Question,Answers,Options
FROM 
(SELECT username,opt1,opt2,ans1,ans2,ques1,ques2  
FROM dbo.tab1) p
    UNPIVOT(Question FOR q1 IN (ques1, ques2))AS unpvt1
    UNPIVOT(Answers FOR answer1  IN (ans1, ans2))AS unpvt2
    UNPIVOT(Options FOR a  IN (opt1, opt2))AS unpvt3
GO
  • 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-16T04:11:25+00:00Added an answer on June 16, 2026 at 4:11 am

    I think you can query this without using UNPIVOT; Please check

    select 
        distinct UserName, 
        Question1 AS Question, 
        Opt1 AS OPT, 
        Ans1 AS Comment 
    From 
        tblFeedback where Question1='Quest1'
    UNION ALL
    select 
        distinct UserName, 
        Question2 AS Question, 
        Opt2 AS OPT, 
        Ans2 AS Comment 
    From 
        tblFeedback where Question2='Quest2'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
I have an application that stores products (reads them from a file, no user
I have problem with base classes in WPF. I try to make a base
I have a complicated problem, and I need help. I have a base case,
I have a problem. There are two classes: struct Base { Base* retain() {
I have a problem with a web page. The introduction of a simple <base
I'm learning C# and I encountered the following problem. I have two classes: base
I have the following problem with inheritance and templates: class Base {}; class Deriv
I've seen that a few instances of this problem have been raised already. However,
In SQL Server, I have a table where a column A stores some data.

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.