15,878,230 members
See more:
```ProductID   Name                   LocationID   Quantity SeqNo
----------- ---------------------- ------------ -------- ----
494         Paint - Silver         3            49       1
495         Paint - Blue           3            49       1
493         Paint - Red            3            51       3
496         Paint - Yellow         3            56       4```

here....by using Rank() function seqNo column was generated...but after 1....i want 2....and then 3....but it skips the numbers....(grouping is on LoationID and Quantity).

I Want Out Like Below
```ProductID   Name                   LocationID   Quantity SeqNo
----------- ---------------------- ------------ -------- ----
494         Paint - Silver         3            49       1
495         Paint - Blue           3            49       1
493         Paint - Red            3            51       2
496         Paint - Yellow         3            56       3```

how should i do that....
Posted
Updated 14-Apr-14 1:46am
v2

## Solution 1

You can use Dense Rank
[^]

According to MSDN:

Returns the rank of rows within the partition of a result set, without any gaps in the ranking. The rank of a row is one plus the number of distinct ranks that come before the row in question.

VB
```SELECT
ProductID,
Name,
LocationID,
Quantity,
DENSE_RANK() OVER (ORDER BY LocationID, Quantity ASC) AS Rank
FROM
Products
ORDER
BY LocationID, Quantity;```

v3

## Solution 2

try query given below in comments...
Happy Coding!
:)

Aarti Meswania 14-Apr-14 7:58am
WITH a as
(
SELECT 49 as qty, 'a' as nm UNION ALL
SELECT 51 as qty, 'b' as nm UNION ALL
SELECT 49 as qty, 'c' as nm UNION ALL
SELECT 50 as qty, 'd' as nm
)
SELECT qty,nm,row_number() OVER (partition BY srno order by qty,nm) from
(
SELECT qty,nm, row_number() OVER (partition BY qty order by nm) srno from a
) as temp
order by qty,nm