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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:10:38+00:00 2026-06-04T07:10:38+00:00

I have a table like the following in SQL Server 2008 AMID TierLevel ——–

  • 0

I have a table like the following in SQL Server 2008

  AMID                TierLevel
 --------            -------------
  999                 GOLD
  1000                SILVER   
  1000                GOLD
  1000                PLATINUM
  1000                BRONZE
  1001                GOLD
  1001                SILVER
  1002                SILVER
  1003                GOLD

Now I want to Update this table like the following

  AMID                TierLevel
 --------            -------------
  999                 GOLD
  1000               PLATINUM  
  1000               PLATINUM
  1000               PLATINUM
  1000               PLATINUM
  1001                GOLD
  1001                GOLD
  1002                SILVER
  1003                GOLD

Here the conditions are

  • I want unique Tier value for the same AMID, and the Tier values should be selected in priority base like

    1. PLATINUM
    2. GOLD
    3. SILVER
    4. BRONZE
  • It means if it is having the highest one present in its Tier values then select that. Like I shown in the second table, Platinum for 1000 and Gold for 1001..

please help me with this

Thanks,
Harry

  • 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-04T07:10:39+00:00Added an answer on June 4, 2026 at 7:10 am

    I would do this using a temporary table to store the rank of each Tier:

    DECLARE @Rank TABLE (ID INT NOT NULL PRIMARY KEY, Name VARCHAR(10) NOT NULL)
    INSERT @Rank VALUES (1, 'PLATINUM'), (2, 'GOLD'), (3, 'SILVER'), (4, 'BRONZE')
    
    ;WITH T AS
    (   SELECT  AMID, TierLevel, MIN(ID) OVER(PARTITION BY AMID) [MinID]
        FROM    #T
                INNER JOIN @Rank
                    ON Name = TierLevel
    )
    UPDATE  T
    SET     TierLevel = Name
    FROM    T
            INNER JOIN @Rank
                ON ID = MinID
    WHERE   TierLevel <> Name
    

    This was done using the following sample data:

    CREATE TABLE #T (AMID INT, TierLevel VARCHAR(10))
    INSERT #T VALUES 
        (999, 'GOLD'), 
        (1000, 'SILVER'), 
        (1000, 'GOLD'), 
        (1000, 'PLATINUM'), 
        (1000, 'BRONZE'),
        (1001, 'GOLD'),
        (1001, 'SILVER'),
        (1002, 'SILVER'),
        (1003, 'GOLD')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sql server 2008 db table FILE_DETAILS in following format. ID FileName Filesize_in_MB
I'd like some help writing the following sproc: I have SQL Server 2008 sproc
In SQL Server 2008, I have the following tables: CREATE TABLE samples (SampleID int,
I am using SQL Server 2008 . I have a table with the following
I am using SQL Server 2008. I have a Student table in which there
I have a SQL Server 2008 database. There is a table called Documents with
I'm using SQL Server 2008 and would like to have a user defined function
I have a question. I have a SQL Server 2008 table with a field
I am on SQL Server 2008 and I have a table containing WA metrics
We have a SQL server 2008 and one of the tables, say table 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.