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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:17:26+00:00 2026-05-18T02:17:26+00:00

I’m having a really hard time finding any examples that are close to what

  • 0

I’m having a really hard time finding any examples that are close to what I’m doing, or I’m simply not understanding the examples I’m finding.

I have a research database that contains a persons responses to multiple questions at different points in time. ‘Admin#’ below represents which “administration” of the test the data represents. Or you can think of it as containing which ‘time’ the test was given, for example, time1, time2, time3

RespondentID# Admin# Question1 Question2 Question3 Question4 Question5
            1      1     A         B        C          D         E
            1      2     E         D        C          B         A
            1      3     Q         W        E          R         T
            2      1     Z         X        C          V         B
            2      2     P         O        I          U         Y
            2      3     Y         H        N          U         J

What I need to do now is arrange this data so that each set of responses for a particular respondent is in the same row. So we’d take the 5 question fields and turn them into 15 question fields,

RespondentID# Admin1Question1 Admin1Question2 Admin1Question3 Admin1Question4 Admin1Question5 Admin2Question1 Admin2Question2 Admin2Question3 Admin2Question4 Admin2Question5 Admin3Question1 Admin3Question2 Admin3Question3 Admin3Question4 Admin3Question5 

As you can see, every field that begins with Admin1 would correspond to the row in the example above that has a Admin# value of 1.

Please forgive me if I’m not explaining this properly.

To further complicate matters, the maximum number of “administrations” or “times” can increase in the future. Currently it is 3, but it is possible that the same test could be administered 4, 5 or more times in the future. Whatever solution used for this problem can be static and then updated by hand to account for additional “times” in the future, but it would be awesome if the solution dynamically accounted for an unspecified number of “times”.

This data is stored in a MS SQL 2005 database, so tsql is obviously an option, but if a better solution exists in C# or LINQ (the overall project is an asp.net app), I’m open to that as well. Whatever you think works best! 🙂

Thanks so much for reading my question!

  • 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-18T02:17:26+00:00Added an answer on May 18, 2026 at 2:17 am

    The basic approach I’m following is to manually pivot using code like:

    select RespondentID,
        min(case when Admin=1 then Question1 else null end) Admin1_Question1,
        min(case when Admin=2 then Question1 else null end) Admin2_Question1,
        min(case when Admin=3 then Question1 else null end) Admin3_Question1
    from tests
    group by RespondentID
    

    So, using a dynamic t-sql statement we build and execute the query for this as follows:

    declare @select varchar(max)
    
    select @select = coalesce(@select+',','')+
        'min(case when Admin='+a+' then '+q+' else null end) as [Admin'+a+'_'+q+']'
    from (select distinct cast(Adminas varchar(10)) a from tests) p1
        cross join (
        select 'Question1' q union
        select 'Question2' union
        select 'Question3' union
        select 'Question4' union
        select 'Question5'
        ) p2
    order by a, q
    
    
    declare @sql varchar(max)
    set @sql = 'select RespondentID, '+@select+' from tests group by RespondentID'
    
    execute(@sql)
    

    It’s not the most dynamic t-sql solution available, but it should work!

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

Sidebar

Related Questions

No related questions found

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.