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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:41:26+00:00 2026-06-05T11:41:26+00:00

Given the two sample tables here: Tickets Table ID User Description 0 James This

  • 0

Given the two sample tables here:

Tickets Table

ID  User    Description

0   James   This is a support ticket
1   Fred    This is a ticket too

Properties Table

ID  TicketID    Label           Value

0   0           Engineer        Scott
1   1           Engineer        Dale
2   0           Manu            Dell
3   1           Manu            HP
4   0           OS              Windows
5   1           OS              Linux

How can I arrive at a view like this:

ID  User    Description                 Engineer    Manu    OS

1   James   This is a support ticket    Scott       Dell    Windows
2   Fred    This is a ticket too        Dale        HP      Linux

It is important to note that the properties table would not always be the same. Some “Tickets” may have properties that others do not.

Is this even possible?

  • 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-05T11:41:28+00:00Added an answer on June 5, 2026 at 11:41 am

    You can perform this with a PIVOT. When doing the PIVOT you can do it one of two ways, with a Static Pivot that you will code the rows to transform or a Dynamic Pivot which will create the list of columns at run-time:

    Static Pivot (See SQL Fiddle for Demo):

    select id, [user], [engineer], [manu], [OS]
    from 
    (
        select t.id
            , t.[user]
            , p.ticketid
            , p.label
            , p.value
        from tickets t
        inner join properties p
            on t.id = p.ticketid
    ) x
    pivot
    (
        min(value)
        for label in ([engineer], [manu], [OS])
    ) p
    

    Or you can use a Dynamic Pivot (See SQL Fiddle for Demo):

    DECLARE @cols AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX);
    
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(p.label) 
                        from tickets t
                        inner join properties p
                            on t.id = p.ticketid
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)') 
            ,1,1,'')
    
    set @query = 'SELECT id, [user], ' + @cols + ' from 
                 (
                     select t.id
                            , t.[user]
                            , p.ticketid
                            , p.label
                            , p.value
                        from tickets t
                        inner join properties p
                            on t.id = p.ticketid
                ) x
                pivot 
                (
                    min(value)
                    for label in (' + @cols + ')
                ) p '
    
    execute(@query)
    

    Both query will return the same results.

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

Sidebar

Related Questions

Given are two tables, Table A containing customerid , lastchange , internallink Table B
Given a simple case of two tables - Term and Definition - where Term
I want to fetch a data from two tables even if the second table
This query here is executed on 3 tables(students) one which makes a zero on
I've got two tables. Table B has a one to many relationship with Table
I need help here in a multiplication table program. The program asks the user
I have two tables like this: Table1ID Table2ID Table1ID SomeDate -------- ------------------------------ 1 1
The Setup I have two tables, USERS and PETS . each user has an
Here's my simple SQL question... I have two tables: Books ------------------------------------------------------- | book_id |
I have a two tables. One table is actually populated by daily events while

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.