Click here to Skip to main content
15,867,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to generate one column as Sl.No. (Question column in below data) This column has to generate based on the group by rows.

For Example,

In "A" group, i have 4 Rows. So want to generate 1,2,3,4.
In "B" group, i have 7 Rows. So i want to generate 1,2,3,4,5,6,7.

I want to generate "n" number of group dynamically.

How to do this in SQL Query..?

Example data:
-------------
ID Code Sl.No ? Role EmpNo
1000 A 1 Manager 9001
1002 A 2 Manager 9002
1003 A 3 Manager 9003
1004 B 1 Asst.Mgr 9004
1005 B 2 Asst.Mgr 9005
1006 B 3 Asst.Mgr 9006
1007 B 4 Asst.Mgr 9007
1008 B 5 Asst.Mgr 9008
1009 B 6 Asst.Mgr 9009
1010 B 7 Asst.Mgr 9010
1011 B 8 Asst.Mgr 9011
1012 C 1 Consultant 9012
1013 C 2 Consultant 9013
1014 C 3 Consultant 9014
1015 C 4 Consultant 9015
1016 C 5 Consultant 9016
1017 C 6 Consultant 9017
Posted
Updated 3-Oct-22 1:56am

Hi,
Check this[^] post. Its doing exactly the same.
 
Share this answer
 
Comments
gani7787 24-Oct-11 8:44am    
Sorry. I didn't understand this logic.
my question is simple and simple SQL statement.
I want the query as simple SQL Statement...
How to dot this....?
ROW_NUMBER() OVER ( PARTITION BY [Code] ORDER BY [ID])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900