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 |
|
disha
Starting Member
34 Posts |
Posted - 2009-12-17 : 07:35:56
|
| i need to create a period bucket using the start date and saysdate and i want the output as below .please advise how to achieve this using case statement or is there any other way please suggest the correct syntax1 day2 days3 days4 days5 days6 days7 days8D - 1M2 Months3 Months4 Months5 Months6 Months7 Months8 Months9 Months10 Months11 Months12 Months1-2 Years2-3 Years3-4 Years4-5 YearsBeyond 5Ys |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2009-12-17 : 08:30:21
|
| You will need to create a large CASE statement... (I dont know if you mean a Function or another field you have by "SAYSDATE", you might be trying to get a system time...dunno, just replace where applicable.)Sample...Case WHEN datediff(d,[Start Date], [SYSDATE]) = 1 then '1 Day'WHEN datediff(d,[Start Date], [SYSDATE]) = 2 then '2 Days'.....WHEN datediff(d,[Start Date], [SYSDATE]) >= 8 AND datediff(m,[Start Date], [SYSDATE]) <= 1then '8D - 1M'WHEN datediff(m,[Start Date], [SYSDATE]) = 2 then '2 Months'.....When datediff(y,[Start Date], [SYSDATE]) BETWEEN 1 AND 2 then '1-2 Years'.....ELSE 'Beyond 5Ys'ENDEDIT: You May need to add a CASE for things happening on the same day, otherwise they will end up in the 'Beyond 5Ys' group |
 |
|
|
|
|
|
|
|