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.
| Author |
Topic |
|
shaaquille
Starting Member
4 Posts |
Posted - 2009-09-08 : 01:44:57
|
| hi every body m new to this forum and this is my 1st posti have to write a query "i have to take the day on which an employee was hired from hiredate and then i have to order it by weekdays like monday shd b 1st and so on " i have written this query bt it wrks fr wednesday only which is the 1st record...--------------------------------select ename,sal,hiredate,to_char(hiredate,'DAY'), case to_char(hiredate,'DAY') when 'MONDAY' then 1 when 'TUESDAY' then 2 when 'WEDNESDAY' then 3 when 'THURSDAY' then 4 when 'FRIDAY' then 5 when 'SATURDAY' then 6 when 'SUNDAY' then 7 END DAY FROM EMP order by DAY------------------------------------thnx in advanceregards ! |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-09-08 : 02:42:41
|
| Hi Try thisselect ename,sal,hiredate, datepart(weekday,hiredate) as Day from EMPorder by datepart(weekday,hiredate)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-08 : 02:43:18
|
What is to_char()?I don't know in SQL Server... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-08 : 03:13:08
|
quote: Originally posted by webfred What is to_char()?I don't know in SQL Server... No, you're never too old to Yak'n'Roll if you're too young to die.
It is used in ORACLE which OP usesMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-08 : 03:15:37
|
quote: Originally posted by shaaquille hi every body m new to this forum and this is my 1st posti have to write a query "i have to take the day on which an employee was hired from hiredate and then i have to order it by weekdays like monday shd b 1st and so on " i have written this query bt it wrks fr wednesday only which is the 1st record...--------------------------------select ename,sal,hiredate,to_char(hiredate,'DAY'), case to_char(hiredate,'DAY') when 'MONDAY' then 1 when 'TUESDAY' then 2 when 'WEDNESDAY' then 3 when 'THURSDAY' then 4 when 'FRIDAY' then 5 when 'SATURDAY' then 6 when 'SUNDAY' then 7 END DAY FROM EMP order by DAY------------------------------------thnx in advanceregards !
What is wrong with simple Order by hiredate?MadhivananFailing to plan is Planning to fail |
 |
|
|
shaaquille
Starting Member
4 Posts |
Posted - 2009-09-08 : 19:23:20
|
| hi thanx fr ur replies ....nthing wrong vd the hiredate :)actually i was preparing fr oracle sql course and it was there in the exercise...and datepart is not wrking in oracle sql...besides i havent read this function uptill now so thr must be a solution to it with simple functions ....looking frward to ur replies .thnxregards ! |
 |
|
|
shaaquille
Starting Member
4 Posts |
Posted - 2009-09-08 : 19:33:29
|
| hiwell sm how i have managed to do it ...------------------------select ename,sal,hiredate,to_char(hiredate,'D'),to_char(hiredate,'DAY'),case to_char(hiredate,'D') when '4' then 3 when '6' then 5 when '1' then 7 when '2' then 1 when '3' then 2 when '5' then 4 when '7' then 6 END dda FROM EMP order by dda -----------------------it may help sm1 :)thnx fr ur help !regards ! |
 |
|
|
|
|
|
|
|