Execute a action on the first day of the month !?

  • Hi,

    I work with sql server 2005 and i'm a beginner!

    I have a stored procedure with some condition and i must to do an action on the first day on the month ...for each month !

    How i can know if the day is the first day of the month in t sql ?

    Thanks for your time

    Christ

  • select DATEPART("dd",GETDATE()) will give you the day of the date. You can check that to see if its the first of the month.

    "Keep Trying"

  • Does the whole procedure get executed only on the first day of the month, or is there some part of it that only gets executed on the first day of the month?

    If the first, then set up your job to run on the first day of the month.

    If the second, then the previous poster already showed you how to do it.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • HI all,

    thanks for all that's work perfectly !

    here is it my little code in my sp

    -- DETERMINE IF WE HAVE THE FRIST DAY OF THE MONTH

    SET @day = (select DATEPART("dd", GETDATE()))

    IF( @day = 1) --23

    BEGIN

    -- WE INSERT SOME VALUE

    EXEC ******** @errorcode=@errorcode OUTPUT

    if @errorcode 0 GOTO DoRollBack

    END

    Thanks for all

    Chris

  • How are you calling the proc? Is it part of a scheduled job? Part of an application? Something else?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Hi,

    it will be a windows task who runs every day night

    have a nice day

    Christ

Viewing 6 posts - 1 through 5 (of 5 total)

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