|
I'd like to query a very large table with millions of records. The query should return the latest transactions for all parts. The final report shows how many quantity on hand for each month. I give the following example for Part SC198 and SC216. Actually we have thousand of parts.
The result for updated date before 3/1/2010 should be
The result for update date before 4/1/2010 should be
The final report should looks like this, [Part Number] Jan Feb March April May ... SC198 70 70 100 100 200 SC216 50 50 80 60 60 ... I tried
(comments are locked)
|
(comments are locked)
|
|
This will give you what you want for dates before 2010/05/05 - obviously just change the date as you want. You haven't specified what SQL Server version you're on - this is a 2005+ query as it makes use of the windowed function 'ROW_NUMBER'
(comments are locked)
|
|
How about
(comments are locked)
|


You've just slyly edited this to turn it into a completely different question. You need to research pivot now.