Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Make Stored Proc not do anything using IF

Author  Topic 

edyl
Starting Member

35 Posts

Posted - 2012-11-13 : 18:12:10
Hello Everyone,

In my stored procedure I want a block to do nothing if its Sunday or Monday but do its regular "inserts and updates" for rest of the days in the week. I have done some thing that gets the work done, but it doesn't seem to be a clean way to do it. Is there a better way to do it. Here is what I did,


Create procedure MyStoredProc
AS
BEGIN
... ... ...
... ... ...
declare @today varchar(10)
set @today = DATENAME(DW,GETDATE())
;

IF @today = 'Sunday' OR @today = 'Monday'
BEGIN
PRINT 'No Update Required'
END;
ELSE
BEGIN
... ... ...
"My Regular Inserts and Updates"
... ... ...
END


I am avoiding the regular updates and inserts on Sundays and Mondays by simply allowing my script to go to somewhere else not absolutely required for it to go to - here printing the message 'No Update Required'. I would rather not print this message if I can.

Is there a better/cleaner way to handle this type of situation? Any suggestions and recommendations highly appreciated.

Thanks.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-11-13 : 18:17:50
[code]CREATE PROCEDURE MyStoredProc
AS
IF DATENAME(DW,GETDATE()) IN('Sunday','Monday') RETURN;
... ... ...
"My Regular Inserts AND Updates"
... ... ... [/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-11-14 : 07:14:55
i prefer logic like
IF DATEDIFF(dd,0,GETDATE())%7 > 4 RETURN
...

as its independent of language and regional settings

http://visakhm.blogspot.in/2012/08/creating-server-independent-day.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-14 : 07:17:09
quote:
Originally posted by visakh16

i prefer logic like
IF DATEDIFF(dd,0,GETDATE())%7 > 4 RETURN
...

as its independent of language and regional settings

http://visakhm.blogspot.in/2012/08/creating-server-independent-day.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Well,well!! It's about time!!! You do know that SQL Team just isn't the same without you around, don't you?!?

Welcome back!
Go to Top of Page

edyl
Starting Member

35 Posts

Posted - 2012-11-14 : 11:13:56
Thank you much.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-11-15 : 05:42:47
quote:
Originally posted by sunitabeck

quote:
Originally posted by visakh16

i prefer logic like
IF DATEDIFF(dd,0,GETDATE())%7 > 4 RETURN
...

as its independent of language and regional settings

http://visakhm.blogspot.in/2012/08/creating-server-independent-day.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Well,well!! It's about time!!! You do know that SQL Team just isn't the same without you around, don't you?!?

Welcome back!


Thank you
Just dropped in for checking mails...
I'm still in vacation with the newest member of my family ...our lil Angel

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -