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

The Archive Base Latest Questions

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

I have a problem in SQL Server 2005: Suppose I have the table PLAYER

  • 0

I have a problem in SQL Server 2005:

Suppose I have the table PLAYER (string player, int score, bool Active) and the this query :

SELECT PLAYER.player AS NAME,
   PLAYER.score AS SCORE,
   POSITION = CASE WHEN PLAYER.Active THEN RANK()OVER(ORDER BY score desc) else NULL end
from PLAYER

The problem is that when the player is not active, the positions generated are not consecutive.

For example :

JOHN,10000,1
PETER,5000,NULL (NOT ACTIVE)
CHARLES,2500,3 (SHOULD HAVE POSITION 2, NOT 3)

Sorry for my terrible English, I hope I have explained my point

  • 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:40:08+00:00Added an answer on June 4, 2026 at 7:40 am
    declare @Player table
    (
      player varchar(20),
      score int,
      state int
    )
    
    insert into @Player values ('JOHN', 10000, 1)
    insert into @Player values ('PETER', 5000, NULL)
    insert into @Player values ('PAUL', 5000, 2)
    insert into @Player values ('CHARLES', 2500, 1)
    
    select player as Name,
           score,
           case
              when state = 1 then
                rank() over(partition by state order by score desc)
              else null
           end as position
    from @Player     
    

    Result:

    Name                 score       position
    -------------------- ----------- --------------------
    PETER                5000        NULL
    JOHN                 10000       1
    CHARLES              2500        2
    PAUL                 5000        NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using sql-server 2005 and ASP.NET with C#. I have Users table with userId(int),
I have a problem with string to datetime conversion in SQL Server 2005. If
How can I query the database culture (SQL Server 2005) ? I have problems
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
I have recently learned that sql server 2005 does not support UTF8: UTF8 problem
I am having a problem with a trigger in SQL Server 2005, I have
I have a sql server 2005 table called ZipCode, which has all the US
I have a problem inserting a datetime format variable to Sql Server 2005 database.
I have a simple problem when querying the SQL Server 2005 database. I have
I have a problem. I have an application in C# with SQL SERVER 2005

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.