In my last post (Below link), I've tried to use the ROW_NUMBER ORDER BY and finally got the required solution. See the following link:
Get Wages Yearly Increment Column Wise Using Sql
Now I am trying to use the following query in Sql server 2000, just for demonstration purpose. I know, ROW_NUMBER ORDER BY can't be used in it. And after some googling, tried to use the following for Sql server 2000: (1st query)
SELECT k.ID, k.[Name], m.Amt,
(SELECT COUNT(*) FROM EmpIncrement l WHERE l.EmpID <= m.EmpID) as RowNum
FROM EmpIncrement m
JOIN Employee k ON m.EmpID = k.ID
And I got this output:
ID Name Amt RowNum
1 John 2000 2
2 Jack 8000 4
1 John 1000 2
2 Jack 4000 4
Similarly when I use the following with ROW_NUMBER ORDER BY, then it shows different output: (2nd query)
SELECT k.ID, k.Name, m.Amt,
ROW_NUMBER() OVER (PARTITION BY EmpID ORDER BY DATEPART(yy,IncrementDate)) as RowNum
FROM EmpIncrement m
JOIN Employee k ON k.ID = m.EmpID
Output:
ID Name Amt RowNum
1 John 1000 1
2 John 2000 2
1 Jack 4000 1
2 Jack 8000 2
So it's noticed that the grouping for the employee ids (RowNum) are different in both the queries where the output of the second query is correct. I would like to know the difference of both the queries output and if the 1st query is equivalent to ROW_NUMBER ORDER BY. Thanks.
Note: I didn't include the table structure and sample data here again. Never mind - You can see the earlier post for that.