Question : sql server order by

I have a problem in executing this statement if  Order by clause is specified. If I comment it out it runs fine.
If order by is included i get  "multipart identifier not bound".. (Looks like its not able to identify the field)
I am using SQL Server 2005

SELECT *
FROM
   (SELECT  e.EmailID,  e.Name,
       ROW_NUMBER() OVER(ORDER BY e.ID) as RowNum
    FROM  tblEmails e LEFT OUTER JOIN  tblTemplates  t ON e.TemplateID = t.TemplateID  
   ) as EmailInfo       
WHERE  RowNum Between 1 AND 100   order by e.Datesent  

(If order by e.datesent is commented it works fine)

Answer : sql server order by

try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
SELECT *
FROM
   (SELECT  e.EmailID,  e.Name,
       ROW_NUMBER() OVER(ORDER BY e.ID) as RowNum,DataSent
    FROM  tblEmails e 
    LEFT OUTER JOIN  tblTemplates  t ON e.TemplateID = t.TemplateID  
   ) as EmailInfo       
WHERE  RowNum Between 1 AND 100   
order by Datesent
Random Solutions  
 
programming4us programming4us