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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:31:38+00:00 2026-05-17T15:31:38+00:00

Hail to the fellow programmers and query writers, I have this beautiful query SELECT

  • 0

Hail to the fellow programmers and query writers,

I have this beautiful query

SELECT ID, [1] AS coL1, [15] AS coL2, [2] AS coL3, [16] AS coL4, [12] AS coL5
FROM MY_TABLE
PIVOT (sum(INT_VALUE) FOR FUND_CODE IN ([1],[2],[15],[16],[12])) AS p
--GROUP BY ID, [1] , [15]  , [2] , [16] , [12] 
ORDER BY ID ASC

That returns me data like this:

10001      182       NULL      NULL      NULL
10001      NULL      81        NULL      NULL
10001      NULL      NULL      182       NULL
10001      NULL      NULL      NULL      81
10002      165       NULL      NULL      NULL
10002      NULL      73        NULL      NULL
10002      NULL      NULL      165       NULL
10002      NULL      NULL      NULL      73

The 10001 and 10002 are two primary keys, and I’d like to show my data like this:

10001      182       81      182      81
10002      165       73      165      73

I tried this commented GROUP BY to no avail.
Any hints? Does it involve COALESCE?

  • 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-17T15:31:39+00:00Added an answer on May 17, 2026 at 3:31 pm

    Just in CASE…

    SELECT ID,
    SUM(CASE WHEN FUND_CODE = 1 THEN VR_MOVIMENTACAO_QUOTA ELSE 0 END) coL1,
    SUM(CASE WHEN FUND_CODE = 15 THEN VR_MOVIMENTACAO_QUOTA ELSE 0 END) coL2,
    SUM(CASE WHEN FUND_CODE = 2 THEN VR_MOVIMENTACAO_QUOTA ELSE 0 END) coL3,
    SUM(CASE WHEN FUND_CODE = 16 THEN VR_MOVIMENTACAO_QUOTA ELSE 0 END) coL4,
    SUM(CASE WHEN FUND_CODE = 12 THEN VR_MOVIMENTACAO_QUOTA ELSE 0 END) coL5
    
    FROM MY_TABLE
    GROUP BY ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hail! I want to fetch image from NOT PUBLIC Google Site's page. I'm using
hail, i have a problem to serve file with PHP into client. that when
Hail Stack! I'm developing a component in Flash (CS5). This one isn't useful, it's
I have some ASP.Net code that defines a server-side checkbox like this: <asp:CheckBox ID=_chkWindAndHail
What's a good way to persist state when restarting a crashed process? I have
I'm working on an application that will have attachments, and I would like to
I have a SharePoint list that gets installed by a feature. I need to
I have a perl .exe file that I was to run every ten minutes.
Hail Stack!! I'm developing a framework for my coworkers and I'm having trouble documenting
Hail Stack! I'm having a hard time trying to figure out why my treeview

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.