Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Date and case loop

 
   Database Help (Home) -> Programming RSS
Next:  buy no prescription cialis no prescription cialis..  
Author Message
freddy

External


Since: May 17, 2008
Posts: 2



(Msg. 1) Posted: Sat May 17, 2008 4:33 pm
Post subject: Date and case loop
Archived from groups: microsoft>public>sqlserver>programming (more info?)

My date work but I need to put it in a case loop, can anyone help me.

Declare @DayOfWeek int
Declare @dayname varchar(10)
set @DayOfWeek = datepart(dw, getdate())
case
When @DayOfWeek = 1 Then @dayname ='Sunday'
When @DayOfWeek = 2 Then @dayname ='Monday'
When @DayOfWeek = 3 Then @dayname ='Tuesday'
When @DayOfWeek = 4 Then @dayname ='Wednesday'
When @DayOfWeek = 5 Then @dayname ='Thursday'
When @DayOfWeek = 6 Then @dayname ='Friday'
When @DayOfWeek = 7 Then @dayname ='Saturday'
End
print @dayname

Thanks
Freddy

 >> Stay informed about: Date and case loop 
Back to top
Login to vote
Alex Kuznetsov

External


Since: Jan 10, 2008
Posts: 640



(Msg. 2) Posted: Sat May 17, 2008 7:34 pm
Post subject: Re: Date and case loop [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On May 17, 7:26 pm, freddy wrote:
> I need the case to show if its 1 than it's Sunday or 2 for Monday and so on....
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
> > Why do you need to do all of that?
>
> > DECLARE @DayName VARCHAR(10);
> > SELECT @DayName = DATENAME(DW, CURRENT_TIMESTAMP);
> > PRINT @DayName;
>
> > "freddy" wrote in message
> >
> > > My date work but I need to put it in a case loop, can anyone help me.
>
> > > Declare @DayOfWeek int
> > > Declare @dayname varchar(10)
> > > set @DayOfWeek = datepart(dw, getdate())
> > > case
> > > When @DayOfWeek = 1 Then @dayname ='Sunday'
> > > When @DayOfWeek = 2 Then @dayname ='Monday'
> > > When @DayOfWeek = 3 Then @dayname ='Tuesday'
> > > When @DayOfWeek = 4 Then @dayname ='Wednesday'
> > > When @DayOfWeek = 5 Then @dayname ='Thursday'
> > > When @DayOfWeek = 6 Then @dayname ='Friday'
> > > When @DayOfWeek = 7 Then @dayname ='Saturday'
> > > End
> > > print @dayname
>
> > > Thanks
> > > Freddy

Why do it yourself if the system will do it for you?

http://msdn.microsoft.com/en-us/library/ms174395.aspx

 >> Stay informed about: Date and case loop 
Back to top
Login to vote
Aaron Bertrand [SQL Serve

External


Since: Jan 10, 2008
Posts: 2166



(Msg. 3) Posted: Sat May 17, 2008 7:48 pm
Post subject: Re: Date and case loop [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Why do you need to do all of that?

DECLARE @DayName VARCHAR(10);
SELECT @DayName = DATENAME(DW, CURRENT_TIMESTAMP);
PRINT @DayName;




"freddy" wrote in message

> My date work but I need to put it in a case loop, can anyone help me.
>
> Declare @DayOfWeek int
> Declare @dayname varchar(10)
> set @DayOfWeek = datepart(dw, getdate())
> case
> When @DayOfWeek = 1 Then @dayname ='Sunday'
> When @DayOfWeek = 2 Then @dayname ='Monday'
> When @DayOfWeek = 3 Then @dayname ='Tuesday'
> When @DayOfWeek = 4 Then @dayname ='Wednesday'
> When @DayOfWeek = 5 Then @dayname ='Thursday'
> When @DayOfWeek = 6 Then @dayname ='Friday'
> When @DayOfWeek = 7 Then @dayname ='Saturday'
> End
> print @dayname
>
> Thanks
> Freddy
 >> Stay informed about: Date and case loop 
Back to top
Login to vote
freddy

External


Since: May 17, 2008
Posts: 2



(Msg. 4) Posted: Sat May 17, 2008 7:48 pm
Post subject: Re: Date and case loop [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I need the case to show if its 1 than it's Sunday or 2 for Monday and so on....

"Aaron Bertrand [SQL Server MVP]" wrote:

> Why do you need to do all of that?
>
> DECLARE @DayName VARCHAR(10);
> SELECT @DayName = DATENAME(DW, CURRENT_TIMESTAMP);
> PRINT @DayName;
>
>
>
>
> "freddy" wrote in message
>
> > My date work but I need to put it in a case loop, can anyone help me.
> >
> > Declare @DayOfWeek int
> > Declare @dayname varchar(10)
> > set @DayOfWeek = datepart(dw, getdate())
> > case
> > When @DayOfWeek = 1 Then @dayname ='Sunday'
> > When @DayOfWeek = 2 Then @dayname ='Monday'
> > When @DayOfWeek = 3 Then @dayname ='Tuesday'
> > When @DayOfWeek = 4 Then @dayname ='Wednesday'
> > When @DayOfWeek = 5 Then @dayname ='Thursday'
> > When @DayOfWeek = 6 Then @dayname ='Friday'
> > When @DayOfWeek = 7 Then @dayname ='Saturday'
> > End
> > print @dayname
> >
> > Thanks
> > Freddy
>
 >> Stay informed about: Date and case loop 
Back to top
Login to vote
Aaron Bertrand [SQL Serve

External


Since: Jan 10, 2008
Posts: 2166



(Msg. 5) Posted: Sun May 18, 2008 12:27 am
Post subject: Re: Date and case loop [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Didn't my code do that? Did you even try what I posted?


>I need the case to show if its 1 than it's Sunday or 2 for Monday and so
>on....
 >> Stay informed about: Date and case loop 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
While loop? - So I am just starting to learn how to use Database. I need the help of a SQL guru! I have these three tables: CREATE TABLE SB3_ScheduleChange ( emp_num EmpNumType:nvarchar(7) NOT NULL PRIMARY KEY, Monday char(35) NULL, Tuesday char(35) NULL...

How to loop through records - I have @WeekIDFrom and @WeekIDTo as input parameters in a stored procedure. I need to loop through each value between @WeekIDFrom and @WeekIDTo and insert the value into a table, like this: INSERT INTO tblSchedule (WeekID) VALUES (@WeekID) Can someone...

How to loop a temp table? - I have a statement in my stored procedure that has the following as an example - INSERT #TempTableOutput EXEC (@select + @from + @where + @order) How could I then loop through the records of #TempTableOutput to update some blank fields that were..

Loop through Table Records - I'm working on a script that creates a temp table called #tmpList. How can Loop through the records of #tmpList? So far in my using SQL, I've always written SQL statements to just return records and I did my looping with VB. I need to be able to loop....

loop through all table names in all db's - I need to loop through all table names in all db's, but I can't get it to work. Pseudo code: Fetch dbname into @db while (@db) ( Fetch table names in @db..sysobjects into @table while (@table) ( Fetch table names in @db..sysobjects int...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]