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 |
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-06-21 : 02:29:07
|
| If I have to display data week & month wise what query should I write supposeI have data Program_ID, Program_Name, Finish_Date1 A 01-04-20042 B 01-04-20043 C 02-04-20044 D 03-04-20045 E 15-04-20046 F 23-04-2004 Now I want to display data asWeek Program_ID Program_Name1 1 A1 2 B1 3 C1 4 D2 5 E3 6 F |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-21 : 03:18:36
|
| I disagree with your results - shouldn't the 15th be in the 3rd week and the 23rd in the 4th week?This should do it.select (day(Finish_Date) + 6) / 7 as week, ProgramID, ProgramNamefrom ProgramsDuane. |
 |
|
|
vganesh76
Yak Posting Veteran
64 Posts |
Posted - 2004-06-21 : 03:53:35
|
| Try if this works out,select case when (day(Finish_Date) /7.0 ) < 1.0 then 1 else day(Finish_Date) /7 end week , Program_ID,Program_Name from (select 1 Program_ID, 'A' Program_Name, '2004-04-01' Finish_Date unionselect 2, 'B', '2004-04-01' unionselect 3, 'C','2004-04-02' unionselect 4, 'D', '2004-04-03' unionselect 5, 'E', '2004-04-15' unionselect 6, 'F','2004-04-23' ) as tGanesh V.Enjoy working |
 |
|
|
|
|
|
|
|