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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:59:48+00:00 2026-06-15T01:59:48+00:00

I am getting data in the following format from a sql table: DisplayName PropertySystemName

  • 0

I am getting data in the following format from a sql table:

DisplayName     PropertySystemName     PropertyDefaultName     PropertyValue
S1                  P1                    Property 1              Value 1
S1                  P2                    Property 2              Value 2
S1                  P3                    Property 3              Value 3
S1                  P4                    Property 4              Value 4
S1                  P5                    Property 5              Value 5
S1                  P6                    Property 6              Value 6
S1                  P7                    Property 7              Value 7
S1                  P8                    Property 8              Value 8
S1                  P9                    Property 9              Value 9
S1                  P10                   Property 10             Value 10

This is the desired output:

DisplayName   Property 1   Property 2 Property 3
S1               Value 1     Value 2    Value 3

This is the query i have but it does not produce the desired output.

Select me.DisplayName,
     Min(Case PropertySystemName When 'P1' Then PropertyValue End) PropertyDefaultName,
     Min(Case PropertySystemName When 'P2' Then PropertyValue End) PropertyDefaultName,
     Min(Case PropertySystemName When 'P3' Then PropertyValue End) PropertyDefaultName
FROM vManagedEntity me

This is the output of above query:

DisplayName   PropertyDefaultName   PropertyDefaultName PropertyDefaultName
S1               Value 1                   Value 2           Value 3

How do i modify the query in order to produce the desired output without hard coding the Column Header as it is already present in the table.

  • 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-15T01:59:49+00:00Added an answer on June 15, 2026 at 1:59 am

    You cannot use the value from the PropertyDefaultName column as a column header unless you use dynamic sql. Using Dynamic SQL will allow you to pull the column values and the header names directly from the tables:

    DECLARE @cols AS NVARCHAR(MAX),
        @colNames AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX)
    
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(PropertySystemName) 
                        from vManagedEntity
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)') 
            ,1,1,'')
    
    select @colNames = STUFF((SELECT ',' + QUOTENAME(PropertySystemName) 
                              + ' as '+ replace(PropertyDefaultName, ' ', '')
                        from vManagedEntity
                        group by PropertySystemName, PropertyDefaultName
                        order by cast(replace(PropertySystemName, 'P', '') as int)
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)') 
            ,1,1,'')
    
    set @query = 'SELECT DisplayName, ' + @colNames + ' from 
                 (
                    select DisplayName, PropertySystemName,
                       PropertyValue
                    from vManagedEntity
                ) x
                pivot 
                (
                    min(PropertyValue)
                    for PropertySystemName in (' + @cols + ')
                ) p '
    
    execute(@query)
    

    See SQL Fiddle with demo

    The result is:

    | DISPLAYNAME | PROPERTY1 | PROPERTY2 | PROPERTY3 | PROPERTY4 | PROPERTY5 | PROPERTY6 | PROPERTY7 | PROPERTY8 | PROPERTY9 | PROPERTY10 |
    ----------------------------------------------------------------------------------------------------------------------------------------
    |          S1 |   Value 1 |   Value 2 |   Value 3 |   Value 4 |   Value 5 |   Value 6 |   Value 7 |   Value 8 |   Value 9 |   Value 10 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting following error while getting data from dictionary -[__NSCFString objectForKey:]: unrecognized selector
I have the following two methods for getting data from my database: - (void)
I have the following situation. Im getting data from an external system in the
Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
I'm getting data from a CSV file in the format {timestamp}, {data1}, {data2} .
I am getting data from severs in json format but i want that user
I am getting the following exception while adding data into database: org.hibernate.HibernateException: The database
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
how can i getting data from listbox in second form named listform while i
I am getting data nightly from a web service that stores their fields in

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.