October 14, 2012 at 12:59 pm
i have a table and a column with dates. there are multiple dates for same date . these dates are inserted on basis of a procedure run on working days and the time of run is inserted into the date column.
Now i want to make a query to find the first run date of every month for past 2 years from the list of dates in the dates column.
October 14, 2012 at 3:35 pm
scottichrosaviakosmos (10/14/2012)
i have a table and a column with dates. there are multiple dates for same date . these dates are inserted on basis of a procedure run on working days and the time of run is inserted into the date column.Now i want to make a query to find the first run date of every month for past 2 years from the list of dates in the dates column.
To have someone help you, you should assist them is no doing by posting the table definition, some sample data and desired result.
you can do this easily, by clicking on the first link in my signature block and follow the simple instructions (using the T-SQL statements also in the article)
October 15, 2012 at 6:54 am
No much details isn't it.
So very generic answer:
SELECT YEAR(YourDateColumn)
,DATENAME(MONTH,MONTH(YourDateColumn)
,MIN(YourDateColumn) AS [first run date in this month]
FROM [YourTable]
WHERE YourDateColumn >= DATEADD(YEAR,-2,GETDATE())
GROUP BY YEAR(YourDateColumn), MONTH(YourDateColumn)
ORDER BY YEAR(YourDateColumn), MONTH(YourDateColumn)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply