Add auto increment column to SQL select statement?

The code gives me a total of calls for each month. All I want to do is create a column called "Order" that will auto increment for every result returned.


Order   |    Month   |    Open_Calls
    0      | Aug 2009 |      2000
    1      | Sep 2009 |       1700
    2      | Oct 2009 |        1800

   SUBSTRING(CONVERT(varchar(12),CAST(CONVERT(varchar(6),MY.MonthYear,112) + '01' AS datetime)-1, 113),4,8) [Month] 
  ,COUNT(C.Call_No) Open_Calls 
   (SELECT CAST(CAST(Y.number + 2000 as varchar) + '-' + CAST(M.number AS varchar) + '-01' as datetime) MonthYear 
    FROM master..spt_values M INNER JOIN 
         master..spt_values Y ON M.type = 'p' AND M.number BETWEEN 1 AND 12 
                             AND Y.type = 'p' AND Y.number BETWEEN 0 AND 20 
    WHERE CAST(CAST(Y.number + 2000 as varchar) + '-' + CAST(M.number AS varchar) + '-01' as datetime)-1 
                  BETWEEN '2009-09-01' AND '2009-12-31' 
   ) MY 
    LEFT JOIN @cl_call_logging C ON C.TimeDate_Call_Log<MY.MonthYear AND C.Resolve_Time > MY.MonthYear 
GROUP BY MY.MonthYear 

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the following column to your query:

ROW_NUMBER() OVER (order by my.<pk>)  as Order,

where <pk> is the primary key of 'MY'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaduwanAuthor Commented:
LEGEND !! Thanks worked like a charm. Only change was to specify Order as "Order".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.