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
 Transact-SQL (2000)
 select total count if different by 5% than yesterday

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-04-21 : 07:55:46
Clarkson writes "Hi there,

I currently have a query that returns a count for sids in my table that have a null or <0 price on each day. I'm trying to take this query further and just returns those counts for each day where the count is greater than 5% of the previous day and the following day.


My present query is:

Declare @StartDate DateTime
Declare @EndDate DateTime
Declare @CurrentDate DateTime
Declare @WeekDay int
Declare @qdate varchar(20)
Declare @strqry varchar(2000)
Declare @strqry1 varchar(2000)

Select @StartDate = '2005.01.01'
Select @EndDate = '2005.04.15'
Select @CurrentDate = @StartDate

While @EndDate >= @CurrentDate
Begin
Select @WeekDay = DatePart(dw, @currentdate)

IF (@Weekday != 1) and (@weekday != 7)
BEGIN
insert into #datelist values (@currentdate)
end

select @currentdate=dateadd(d, 1, @currentdate)
End


select * from
(select q.qdate as qDate, 'FIXED INCOME' as DataRange, count(q.qsid)as SidCount from qpricetruv2005 q, #datelist d
where d.datecheck = q.qdate and q.qsid > 5000000 and q.qsid <= 890000000 and q.qprice is not null group by q.qdate
UNION ALL
select q.qdate as qDate, 'EQUITY' as DataRange, count(q.qsid) as SidCount from qpricetruv2005 q, #datelist d
where d.datecheck = q.qdate and qsid >= 0 and qsid <= 5000000 and q.qprice is not null group by q.qdate) as overall
order by qdate, datarange

Any ideas how I can factor in the percentage check for the count(qsid) Plus I need to do this check for both 'qsid' ranges in the table Equity and Fixed Income.

Any help would be greatly appreciated!!!

Thanks!!!"
   

- Advertisement -