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)
 Help with stored procedure?

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 =1


Above 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 Larsson
Helsingborg, Sweden
Go to Top of Page

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 union
select
15 union
select
110 union
select
200 union
select
3 union
select
20 union
select
155

select
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
#Details

drop table #details


Duane.
Go to Top of Page

roxcy
Yak Posting Veteran

58 Posts

Posted - 2006-09-27 : 08:11:11
Thnks For ur Reply.
The code really solved my query...
Go to Top of Page
   

- Advertisement -