0

Hi guys I'm trying to count the number of towers in a master property.. but i having problems resetting the count. I only have this code.

SELECT ProjectName,T.TowerName ,
           CONVERT(NVARCHAR(2),RIGHT('00'+CAST(rank() OVER (ORDER BY T.TowerID) AS VARCHAR(3)),2)) AS TowerID   
FROM MasterProperty AS MP 
INNER JOIN Tower AS T ON Mp.MasterPropertyID = T.MasterPropertyID

This is what got.

This is what got.

This what i need.

This what i need

1 Answer 1

3

You can use row_number window function:

select
    t.*,
    row_number() over (partition by ProjectName order by TowerId) whatIwant
from your_table t;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.