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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:32:17+00:00 2026-05-30T01:32:17+00:00

I have report data is that structured as followed: RecID | ReportView1 | Name

  • 0

I have report data is that structured as followed:

RecID | ReportView1           | Name    | Value | Total 
1     | CURRENT_VIEW          | 'Test1' | 10    | 20
1     | PROPOSED_VIEW         | 'Test11'| 20    | 30
1     | POTENTIAL_SAVING_VIEW | null    | null  | 80
2     | CURRENT_VIEW          | 'Test1' | 10    | 20
2     | PROPOSED_VIEW         | 'Test22'| 25    | 35
2     | POTENTIAL_SAVING_VIEW | null    | null  | 70
3     | CURRENT_VIEW          | 'Test1' | 10    | 20
3     | PROPOSED_VIEW         | 'Test33'| 45    | 65
3     | POTENTIAL_SAVING_VIEW | null    | null  | 90

I want to reorder based on TOTAL DECS but only apply for ReportView1 = ‘POTENTIAL_SAVING_VIEW ‘

So the data will be:

NewRecID | RecID | ReportView1           | Name     | Value | Total 
1        | 3     | CURRENT_VIEW          | 'Test1'  | 10    | 20
1        | 3     | PROPOSED_VIEW         | 'Test33' | 45    | 65
1        | 3     | POTENTIAL_SAVING_VIEW | null     | null  | 90
2        | 1     | CURRENT_VIEW          | 'Test1'  | 10    | 20
2        | 1     | PROPOSED_VIEW         | 'Test11' | 20    | 30
2        | 1     | POTENTIAL_SAVING_VIEW | null     | null  | 80
3        | 2     | CURRENT_VIEW          | 'Test1'  | 10    | 20
3        | 2     | PROPOSED_VIEW         | 'Test22' | 25    | 35
3        | 2     | POTENTIAL_SAVING_VIEW | null     | null  | 70

I could probably use joining withiin itself BUT I am just wondering it may be there is an alternative.

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-30T01:32:19+00:00Added an answer on May 30, 2026 at 1:32 am

    (Edited to account for cases with duplicate totals.)

    ;
    WITH atable (RecID , ReportView1   , Name    , Value , Total) AS (
      SELECT 1, 'CURRENT_VIEW         ', 'Test1' , 10    , 20 UNION ALL
      SELECT 1, 'PROPOSED_VIEW        ', 'Test11', 20    , 30 UNION ALL
      SELECT 1, 'POTENTIAL_SAVING_VIEW', null    , null  , 80 UNION ALL
      SELECT 2, 'CURRENT_VIEW         ', 'Test1' , 10    , 20 UNION ALL
      SELECT 2, 'PROPOSED_VIEW        ', 'Test22', 25    , 35 UNION ALL
      SELECT 2, 'POTENTIAL_SAVING_VIEW', null    , null  , 70 UNION ALL
      SELECT 3, 'CURRENT_VIEW         ', 'Test1' , 10    , 20 UNION ALL
      SELECT 3, 'PROPOSED_VIEW        ', 'Test33', 45    , 65 UNION ALL
      SELECT 3, 'POTENTIAL_SAVING_VIEW', null    , null  , 90 UNION ALL
      SELECT 4, 'CURRENT_VIEW         ', 'Test1' , 10    , 20 UNION ALL
      SELECT 4, 'PROPOSED_VIEW        ', 'Test11', 20    , 30 UNION ALL
      SELECT 4, 'POTENTIAL_SAVING_VIEW', null    , null  , 80
    ),
    ranked AS (
      SELECT
        *,
        rnk = MAX(CASE ReportView1 WHEN 'POTENTIAL_SAVING_VIEW' THEN Total END)
              OVER (PARTITION BY RecID)
      FROM atable
    )
    SELECT
      NewRecID = DENSE_RANK() OVER (ORDER BY rnk DESC, RecID),
      RecID,
      ReportView1,
      Name,
      Value,
      Total
    FROM ranked
    ORDER BY
      rnk DESC,
      RecID,
      Total
    

    Output:

    NewRecID  RecID  ReportView1            Name    Value  Total
    --------  -----  ---------------------  ------  -----  -----
    1         3      CURRENT_VIEW           Test1   10     20
    1         3      PROPOSED_VIEW          Test33  45     65
    1         3      POTENTIAL_SAVING_VIEW  NULL    NULL   90
    2         1      CURRENT_VIEW           Test1   10     20
    2         1      PROPOSED_VIEW          Test11  20     30
    2         1      POTENTIAL_SAVING_VIEW  NULL    NULL   80
    3         4      CURRENT_VIEW           Test1   10     20
    3         4      PROPOSED_VIEW          Test11  20     30
    3         4      POTENTIAL_SAVING_VIEW  NULL    NULL   80
    4         2      CURRENT_VIEW           Test1   10     20
    4         2      PROPOSED_VIEW          Test22  25     35
    4         2      POTENTIAL_SAVING_VIEW  NULL    NULL   70
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a report that renders data returned from a stored procedure. Using profiler
I have report that I must convert to PDF using xsl-fo from xml data
I have multiple BIRT reports that obtains the data from the same jdbc data
We have a web application that produces reports. Data are taken from a database.
I have a report where the fields come from data pulled from a SQL
i have to build some financial data report, and for making the calculation, there
I have a report in MS Access where the underlying data in the tables
I have been researching options for printing report-like data via a web application. Some
Is it possible to have a report which has grouping on the underlying data
My SSRS report fetches data from my DATAWAREHOUSE. The ASP.NET application I have is

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.