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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:19:37+00:00 2026-05-26T00:19:37+00:00

Hope you can help… I have data table in this format (Lets refer this

  • 0

Hope you can help…
I have data table in this format (Lets refer this table as ‘Product’)

productid   property_name   property_value  last_updated
p0001           type        p1              05-Oct-2010
p0001           name        Premium         05-Oct-2010
p0001           cost        172.00          05-Oct-2010
p0002           type        p3              06-Oct-2010
p0002           name        standard        06-Oct-2010
p0002           cost        13.00           06-Oct-2010

*(there are like 50 more properties of which i would need 15 atleast in my query. 
However, i just ignore them for this example)*

I would need the data in this format:

productid       type        name            cost
p0001           p1          Premium     172.00
p0002           p3          standard    13.00

I tried with a function and a view to get this format but it takes good few mins to get some 1000 records. Wonder if anyone knows quicker way?

What I tried:

Create function fun1(@productid nvarchar(50)) returns @retdetails table
(
type nvarchar(50) null,
name nvarchar(50) null,
cost nvarchar(50) null,
)
begin
declare
    @type nvarchar(50),
    @name nvarchar(50),
    @cost nvarchar(50),

    select @type=property_value from product where productid=@productid and property_name='type';
    select @name=property_value from product where productid=@productid and property_name='name';
    select @cost=property_value from product where productid=@productid and property_name='cost';

    if isnull(@productid,'')<>''
    begin
        insert @retdetails
            select @type, @name, @cost;
    end;
    return;
end;

then a view

select p.productid, pd.type, pd.name, pd.cost
from (select distinct productid from product) p
cross apply dbo.fun1(p.productid) pd

The slower response might be down to ‘distinct’ but without that I get duplicate records. I would appreciate any suggestion to get a quickier sql response.

Many 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-26T00:19:37+00:00Added an answer on May 26, 2026 at 12:19 am

    You could try this PIVOT approach

    SELECT productid,
           MAX(CASE WHEN property_name = 'type' THEN property_value END) AS type,
           MAX(CASE WHEN property_name = 'name' THEN property_value END) AS name,
           MAX(CASE WHEN property_name = 'cost' THEN property_value END) AS cost
    FROM Product
    GROUP BY productid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope you can help. This has been confounding me for hours. I have
Hope someone can help me with this.. I have a magento store up&running, via
I hope someone can help... This issue has been discussed here and I have
I hope somebody can help me here, I have a table that has the
I really hope someone can help on this because I'm learning cocoa and have
Hope you can help me with this, (again in some cases!) I have a
Hope you can help me with this: So, I have Nivo slider working fine
I hope someone can help with this. I have created a map app that
hope you can help me. I have html markup like this: <a href=error.htm class=button
I hope somebody can help work out to do this. Basically, I have a

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.