SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


first official day of every month for past 3 years


first official day of every month for past 3 years

Author
Message
scottichrosaviakosmos
scottichrosaviakosmos
Old Hand
Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)Old Hand (322 reputation)

Group: General Forum Members
Points: 322 Visits: 691
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.
bitbucket-25253
bitbucket-25253
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15181 Visits: 25280
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)

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Eugene Elutin
Eugene Elutin
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11880 Visits: 5478
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)




_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search