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 |
|
roxcy
Yak Posting Veteran
58 Posts |
Posted - 2006-09-27 : 07:45:16
|
| Hi,I have created a table where i have Table Name Details and column named Days which has following values 4,15,110,200,3,20,155...My condition is to find Days < 7, Days > 7, Days > 90,Days > 180...from the table Details in the column Days.This is the output.< 7 Days = 2, > 7 Days = 1, >90 Days= 2 > 180 days =1Above I have to count How many occurences of > 7 Days, < 7 Days, > 90 days, > 180 days from the Table Details.Could anyone tell me How to do this using stored procedures?Thanks... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-09-27 : 07:48:39
|
| [code]select sum(case when days < 7 THEN 1 else 0 end) '< 7 Days', sum(case when days between 7 and 90 THEN 1 else 0 end) '> 7 Days', sum(case when days between 91 and 180 THEN 1 else 0 end) '>90 Days', sum(case when days > 180 THEN 1 else 0 end) '> 180 Days'from yourtable[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-09-27 : 07:53:45
|
Something along these lines.....create table #Details(Days INT)insert into #Details(Days)select 4 unionselect 15 unionselect 110 unionselect 200 unionselect 3 unionselect 20 unionselect 155select sum(case when Days < 7 then 1 else 0 end) as [< 7 Days], sum(case when Days Between 7 and 90 then 1 else 0 end) as [between 7 Days and 90 Days]from #Detailsdrop table #detailsDuane. |
 |
|
|
roxcy
Yak Posting Veteran
58 Posts |
Posted - 2006-09-27 : 08:11:11
|
| Thnks For ur Reply. The code really solved my query... |
 |
|
|
|
|
|
|
|