Query Numbering

K

Kjuib

I just need a query to Number down the rows giving each
one a unique Number.
How do I go about doing this?
 
J

Joe Fallon

This SQL statement will give you both a record number and a running total of
freight in the Orders table. Modify it to meet your needs after testing it
on Northwind.

SELECT (SELECT COUNT(OrderID) FROM Orders AS temp WHERE temp.OrderID <=
Orders.OrderID) AS Recno, Orders.OrderID, Orders.Freight, (SELECT
Sum(Freight) FROM Orders AS temp WHERE temp.OrderID <= Orders.OrderID) AS
RunningTotal
FROM Orders
ORDER BY Orders.OrderID;


For another solution check out this MSKB Article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;210554
 
S

Steve Schapel

This SQL statement will give you both a record number and a running total of
freight in the Orders table. Modify it to meet your needs after testing it
on Northwind.

SELECT (SELECT COUNT(OrderID) FROM Orders AS temp WHERE temp.OrderID <=
Orders.OrderID) AS Recno, Orders.OrderID, Orders.Freight, (SELECT
Sum(Freight) FROM Orders AS temp WHERE temp.OrderID <= Orders.OrderID) AS
RunningTotal
FROM Orders
ORDER BY Orders.OrderID;


For another solution check out this MSKB Article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;210554
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top