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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:02:20+00:00 2026-05-30T16:02:20+00:00

I have a query that gives me this result: |SystemName |SystemDescription |CertificateType |CertName |CertDate

  • 0

I have a query that gives me this result:

|SystemName    |SystemDescription   |CertificateType |CertName  |CertDate  |
----------------------------------------------------------------------------
| ABC          |Blah-blah ABC       | X             | X-865567  | 1 Jan    |
| ABC          |Blah-blah ABC       | Y             | Y-8a5567  | 2 Jan    |
| ABC          |Blah-blah ABC       | Z             | Z-86af67  | 3 Jan    |
| EFG          |Blah-blah EFG       | X             | X-8kuhkj  | 4 Jan    |
| EFG          |Blah-blah EFG       | Y             | Y-uiiou   | 5 Jan    |
| EFG          |Blah-blah EFG       | Z             | Z-8lkjhu  | 6 Jan    |
----------------------------------------------------------------------------

I need to produce this result:

|SystemName |SystemDescription   | X-Name  | X-Date | Y-Name | Y-Date | Z-Name | Z-Date|
---------------------------------------------------------------------------------------
|ABC        | Blah-blah ABC      |X-865567 | 1 Jan  |Y-8a5567| 2 Jan  |Z-86af67| 3 Jan |
|EFG        | Blah-blah EFG      |X-8kuhkj | 4 Jan  |Y-uiiou | 5 Jan  |Z-8lkjhu| 6 Jan |
----------------------------------------------------------------------------------------

In other words I need to pivot without aggregation and with at least 2 columns not pivoted.
Is it possible to produce this without functions, stored procedures and temp tables?? I know how to easily implement this with a few funcitons, I can come up with solution with temp table.

I wonder if it is possible to get a neat solution using PIVOT??

p.s. this is not a homework, just a brain-teaser -)

  • 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-30T16:02:22+00:00Added an answer on May 30, 2026 at 4:02 pm

    It is not necessary to use PIVOT to do this, sometimes it’s more of a mess to use it than it’s worth. As far as not using aggregate functions – think about it, you want to group your records in terms of SystemName and SystemDescription, you don’t have a choice but to use aggregates. That’s ok though, just use MAX as I have done, you’re going to get the results you want. The only thing you would need to worry about is in the scenario where there are two records with same SystemName, SystemDescription and CertificationType that have different values for CertName or CertDate – in that case you need some way to choose which attributes are selected for the group.

    Here is a non-Pivot example:

    SELECT SystemName,
           SystemDescription,
           MAX([x-Name]) AS [x-Name],
           MAX([x-Date]) AS [x-Date],
           MAX([y-Name]) AS [y-Name],
           MAX([y-Date]) AS [y-Date],    
           MAX([z-Name]) AS [z-Name],
           MAX([z-Date]) AS [z-Date]
    FROM (
        SELECT SystemName, 
               SystemDescription,
               CASE CertificationType WHEN 'X' THEN CertName END AS [x-Name],
               CASE CertificationType WHEN 'Y' THEN CertName END AS [y-Name],
               CASE CertificationType WHEN 'Z' THEN CertName END AS [z-Name],
               CASE CertificationType WHEN 'X' THEN CertDate END AS [x-Date],
               CASE CertificationType WHEN 'Y' THEN CertDate END AS [y-Date],
               CASE CertificationType WHEN 'Z' THEN CertDate END AS [z-Date]
        FROM @yourTable
    ) T
    GROUP BY SystemName, SystemDescription;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have this foreach loop that gives weird result , it displays only
I have a query that I'd like to change so that it gives me
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query which gives a result of about 100 rows. Here is
Say I have this query: SELECT name::text, id::int, pass:bool FROM mytable; which gives me
I am using in C# MYsql .I have query that works if I run
I have a query that is dynamically built after looking up a field list
I have a query that I'm executing from a .NET application to a SQL
I have a query that is currently using a correlated subquery to return the

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.