I have the below SQL code. The DocDate field in the database is of type datetime. I need the data in the DocDate field to be output as a string, and specificaly I want to strip away the time as well as the month and day...I only need the year. I am using this with an asp.net application, where I am using the output of the database to build a filesystem path and one level of the path consists of folders that are named by year (e.g. 1998, 2003, etc.)
However, I'd still like the "ORDER BY req.DocDate" portion of the code to order the results by the acutal datetime informaiton contained in the database.
Using MS SQL Server 2008 & MS Visual Studio 2008.
Thanks in advance!
SELECT req.DocumentTitle, req.Author, req.Organization, req.Description, req.DocDate, req.FollowUp, resp.DocumentID, resp.Organization, resp.DocumentTitle, resp.FileName, resp.FileType
FROM eog_docdb.dbo.Document req
LEFT OUTER JOIN (eog_docdb.dbo.Document_Responder d_r
INNER JOIN eog_docdb.dbo.Document resp
ON resp.DocumentID = d_r.ResponseDocID)
ON req.DocumentID = d_r.DocumentID
WHERE req.CategoryName = 'Information'
AND req.CategorySub1Name = 'Information Bulletins'
AND req.CategorySub2Name IS NULL
ORDER BY req.DocDate;