Hi guys,I hope somebody can help as I am trying to write a procedure in SQL that will be an email reminder sent to users on every 5 th or the month if they don't submit data before.
I am quite new to sql and procedures in particular so I was hoping somebody can help.
I need to:
1.Check the day of the month, if not 5th do nothing
2.Get the date of the prevoious month (get current date - 1 month,set day to 1)this is the funny bit.
I have a field DateEntered,but users only select the month and the year on the acctual page,but when submitted it gets written as a full date and defaults to the 1st of the month.
3.Get the list of hospitals that haven't got data for the previous month
4.Email the hospitals.
DECLARE @.returnDay int;
DECLARE @.DateEntered datetime;
SELECT @.returnDay = DatePart(day,GetDate())
If @.returnDay = 5 (syntax error near 5)
BEGIN
SELECT @.DateEntered = GetDate() - 30
Print DatePart(month, @.DateEntered)
I was hoping somebody could look at this and help me.
thanksYou don't have to get the fifth day of the month at all. When you set up your job to run your proc, just set it Monthly, every 5th day of the month.
You can the get the other date by:
SELECT @.datetime = DATEPART(MM,DATEADD(MM,-1,GETDATE()) + '/01/' + DATEPART(YY,GETDATE()
Then do what you need to do.|||skunked again, (job part)|||Yes, but I am getting this error "Syntax error converting datetime from character string"
I know there is a CONVERT function to do this but suprise,suprise I can't put it properly inside the formula
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment