Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

first official day of every month for past 3 years Expand / Collapse
Author
Message
Posted Sunday, October 14, 2012 12:59 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, June 30, 2014 6:40 AM
Points: 105, Visits: 461
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.
Post #1372527
Posted Sunday, October 14, 2012 3:35 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:28 AM
Points: 5,573, Visits: 24,808
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
Post #1372540
Posted Monday, October 15, 2012 6:54 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1372706
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse