April 23, 2009 at 12:59 am
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
April 23, 2009 at 1:12 am
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"
April 23, 2009 at 6:44 am
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
April 23, 2009 at 7:02 am
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
April 23, 2009 at 7:06 am
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
April 23, 2009 at 7:17 am
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