Numbering multiple dates per delivery I am interested in producing the following view where different delivery dates are numbered.

SalesID    Delivery Date DateNo
SO00000014 2014-02-21    1
SO00000015 2014-02-13    1
SO00000016 2014-01-28    1
SO00000017 2014-03-17    1
SO00000018 2014-02-13    1
SO00000020 2014-03-19    1
SO00000020 2014-03-20    2
SO00000020 2014-03-21    3


My question is how to number different dates associated to a single SalesId like in the 
 SO00000020 above. I am using SQL Server 2008.
Not knowing your data, the view definition would be:

SELECT
    [SalesID],
    [Delivery Date],
    ROW_NUMBER() OVER (PARTITION BY [SalesID] ORDER BY [Delivery Date]) AS DateNo
FROM
    [WhatEverTable]


http://technet.microsoft.com/en-us/library/ms186734(v=sql.105).aspx

ROW_NUMBER() by itself will return a running count of the rows, but when you add the OVER(PARTITION BY [SalesID] ORDER BY [Delivery Date]) it gives a running count per sales id, ordered by the date.

Does that make sense?

EDIT: If you do make this a view, just be aware that the results will be filtered by your WHERE clause. Using your data above, if you queried for sales that occurred after 2014-03-20, SalesID SO00000020 will only have a single entry for 2014-03-21 with a DateNo of 1.

If you need the data to persist regardless of the WHERE clause, you will likely just have to scrap the idea of a view and get creative with the query that accesses the data.