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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:49:08+00:00 2026-05-20T23:49:08+00:00

sorry if this has already been posted but I’ve been through umpteen posts on

  • 0

sorry if this has already been posted but I’ve been through umpteen posts on pivoting the past day and still havn’t been able to get the result i want.

Background:

In short, I am developing a set of tables that will store a questionnaire dynamically.
I wont go into detail of it probably isnt relative.

I basically want to query the table that stores the user input for a set question.
These questions branch off each other allowing me to show columns and rows per question etc.

Anyway this query:

SELECT qr.*, Question   
    FROM QuestionRecord qr
    INNER JOIN 
    QuestionRecord P
    ON P.ID = qr.ParentQuestionRecordId
    JOIN Questions q ON q.ID = qr.QuestionID

Produces this result set :

ID FormRecordId QuestionId ParentQuestionRecordId   Value            Question    
---------------------------------------------------------------------------------------
2     1           31            1                Consultancy      Eligible project costs
3     1           32            2                NULL             Date
4     1           33            2                25000            Cash Costs £
5     1           34            2                NULL             In Kind Costs £
6     1           35            2                25000            Total Costs
7     1           31            1                Orchard day x2   Eligible project costs
8     1           32            7                NULL             Date
9     1           33            7                15000            Cash Costs £
10   1           34            7                NULL             In Kind Costs £
11   1           35            7                15000            Total Costs

I basically want to Pivot(I think) these rows to look like so:

Eligible project costs    Date     Cash Costs £     In Kind Costs   Total Costs
--------------------------------------------------------------------------------
Consultancy               NULL        25000            NULL           25000
Orchard day x2            NULL        15000            NULL           15000

I have tried:

SELECT [Eligible project costs],[Date],[Cash Costs £],[In Kind Costs £],[Total Costs]
FROM
(
    SELECT  qr.*, Question
    FROM QuestionRecord qr
    INNER JOIN 
    QuestionRecord P
    ON P.ID = qr.ParentQuestionRecordId
    JOIN Questions q ON q.ID = qr.QuestionID    
)pvt

PIVOT
(
    MIN(Value)
    FOR Question IN
    ([Eligible project costs],[Date],[Cash Costs £],[In Kind Costs £],[Total Costs])
)pivotTable

but this returns each column on a seperate row:

Eligible project costs    Date     Cash Costs £     In Kind Costs   Total Costs
--------------------------------------------------------------------------------
Consultancy               NULL        NULL              NULL             NULL        
NULL                      NULL        NULL              NULL             NULL 
NULL                      NULL       25000              NULL             NULL
NULL                      NULL        NULL              NULL             NULL
NULL                      NULL        NULL              NULL            25000

So that’s as close as i have managed to get with it, i was wondering if you guys/girls could help me out 🙂

Thanks!

  • 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-20T23:49:09+00:00Added an answer on May 20, 2026 at 11:49 pm

    Try the following changes to your script (strikethrough = deleted, bold = added):

    SELECT [Eligible project costs],[Date],[Cash Costs £],[In Kind Costs £],[Total Costs]
    FROM
    (
        SELECT  qr.*,
          grp = ROW_NUMBER() OVER (PARTITION BY qr.QuestionId ORDER BY qr.ID),
          Value,
          Question
        FROM QuestionRecord qr
        INNER JOIN 
        QuestionRecord P
        ON P.ID = qr.ParentQuestionRecordId
        JOIN Questions q ON q.ID = qr.QuestionID    
    )pvt
    
    PIVOT
    (
        MIN(Value)
        FOR Question IN
        ([Eligible project costs],[Date],[Cash Costs £],[In Kind Costs £],[Total Costs])
    )pivotTable
    

    I think it must give your the result you are after.

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

Sidebar

Related Questions

Sorry if this has already been posted, but I have seen many of them
Sorry if this has already been answered but I could not find it here.
Sorry if this has already been answered, but I can't find it if so.
sorry if this question has already been answered somewhere else, but I couldn't find
I'm sorry if this question has been asked already, but I couldn't find it
I'm sorry if this subject has already been answered, but I couldn't find what
im sorry if this has already been covered, i have had a look but
Sorry if this is has already been ask but I can't find the exact
Sorry if this has been answered already, but I think I actually lack the
Sorry if something similar has been posted here already, but I couldn't really find

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.