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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to verify the date is saturday or sunday.

Author  Topic 

Wilmos
Starting Member

13 Posts

Posted - 2009-11-09 : 14:40:59
Hi all prof in the world,

I would like to write a stored procudure to perform different task according to different day.

LEt say for example, from Monday-Friday, I wish to trigger sp 1, Saturday, sp2 and Sunday sp3.

Is it possible to do that?

Many thanks in adv.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-09 : 14:48:18
Look at the result from:
select datename(weekday,getdate())



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Wilmos
Starting Member

13 Posts

Posted - 2009-11-09 : 14:51:34
wow!!!! Many thanks to webfred for your prompt and prof advice!

It works !! Many thanks. :-)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-11-09 : 14:52:33
Datename is locale dependant.

Consider this

DATEDIFF(DAY, 0, GETDATE()) % 7 / 5



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-09 : 14:53:06
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Wilmos
Starting Member

13 Posts

Posted - 2009-11-09 : 14:57:42
Hi Peso,
May i know wht is the locale dependant meant?
Many thanks!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-09 : 15:04:52
See this:
set language german
select datename(weekday,getdate())
set language english
select datename(weekday,getdate())


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Wilmos
Starting Member

13 Posts

Posted - 2009-11-09 : 15:08:22
wowow!! thank webfred again for your prompt, short but clear and powerful explanation!

thanks.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-09 : 15:45:39
Where are your papers!



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-11-11 : 13:31:57
I assume that checking the date by language is sufficient for your needs. But, you could always use the DATEPART function in conjuction with the @@DATEFIRST function:
SET LANGUAGE Italian;
GO
SELECT @@DATEFIRST, DATEPART(DW, GETDATE());

GO
SET LANGUAGE us_english;
GO
SELECT @@DATEFIRST, DATEPART(DW, GETDATE());
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-11-11 : 14:52:07
[code]-- Returns 0=Mon, 1=Tue, 2=Wed, 3=Thu, 4=Fri, 5=Sat, 6=Sun
select datediff(day,0,getdate())%7[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -