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 2000 Forums
 SQL Server Development (2000)
 adding weekday name to field in database

Author  Topic 

mantisvss
Starting Member

1 Post

Posted - 2002-09-19 : 21:14:59
MSSQL - i have a field in the database of type datetime .. the string is stored as 9/17/2002 ... now what im wanting to do is have another field and have it automatically populated with the weekday name.. so i was thinking i need either a stored procedure or a formula in the field. The problem is that I dont know how to do that... I know how to display the weekday name by using

 
day = (DatePart("w", RS("Date")))
if day = "1" then day = "Sun"
if day = "2" then day = "Mon"
if day = "3" then day = "Tues"
if day = "4" then day = "Wed"
if day = "5" then day = "Thur"
if day = "6" then day = "Fri"
if day = "7" then day = "Sat"



I just need the weekday name in the database so i can sort records by weekday
thanks...


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-19 : 22:22:33
Just use the DateName() function, there's no need to keep it in a separate column:

SELECT DateName(weekday, DateValue) AS WeekDay, * FROM myTable
ORDER BY DateName(weekday, DateValue)


You can find out more about DateName and DatePart in Books Online.

Go to Top of Page

r937
Posting Yak Master

112 Posts

Posted - 2002-09-19 : 22:41:53
just curious, but why do you want to sort on week day name?

maybe it's me, but i'd be weirded out by a report that had totals by

Fri
Mon
Sat
Sun
Thu
Tue
Wed


rudy
http://rudy.ca/
Go to Top of Page
   

- Advertisement -