We help IT Professionals succeed at work.

MS SQL - Incrimental Count on Query results, grouped by BoxID field

Cyber-Drugs
Cyber-Drugs asked
on
369 Views
Last Modified: 2012-05-05
Hi guys 'n gals,

I a query:

SELECT UID, BoxID, Name
FROM tblBoxes

which returns this:

1, 4, Red
2, 4, Orange
3, 8, Red
4, 9, Purple
5, 9, Pink
6, 9, Yellow

I want it to be changed to return this:

1, 4, 1, Red
2, 4, 2, Red
3, 8, 1, Red
4, 9, 1, Purple
5, 9, 2, Pink
6, 9, 3, Yellow


Basically, add an extra column which is an incremental count of from 1 to the total number of BoxID's.

If I haven't made myself clear enough on what I am trying to do, please let me know, and I'll try to better explain myself.

Cheers!
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi VRBones,

If it's easier/faster with Stored Procedures, that's perfeclty fine, as long as it's all within SQL Server.

As for the UID, it's unique, but I can't promise it's ascending.

Author

Commented:
Just tested it, and it does the trick perfectly, cheers!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.