first official day of every month for past 3 years

  • 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.

  • 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[/url]
    Before posting a performance problem please read[/url]

  • 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[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply