SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Make Stored Proc not do anything using IF
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

edyl
Starting Member

32 Posts

Posted - 11/13/2012 :  18:12:10  Show Profile  Reply with Quote
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

USA
15654 Posts

Posted - 11/13/2012 :  18:17:50  Show Profile  Visit robvolk's Homepage  Reply with Quote
CREATE PROCEDURE MyStoredProc
AS
IF DATENAME(DW,GETDATE()) IN('Sunday','Monday') RETURN;
    ... ... ...
    "My Regular Inserts AND Updates"
    ... ... ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 11/14/2012 :  07:14:55  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/14/2012 :  07:17:09  Show Profile  Reply with Quote
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

32 Posts

Posted - 11/14/2012 :  11:13:56  Show Profile  Reply with Quote
Thank you much.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 11/15/2012 :  05:42:47  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000