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 |
|
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 DateTimeDeclare @EndDate DateTimeDeclare @CurrentDate DateTimeDeclare @WeekDay intDeclare @qdate varchar(20)Declare @strqry varchar(2000)Declare @strqry1 varchar(2000)Select @StartDate = '2005.01.01'Select @EndDate = '2005.04.15'Select @CurrentDate = @StartDateWhile @EndDate >= @CurrentDateBeginSelect @WeekDay = DatePart(dw, @currentdate)IF (@Weekday != 1) and (@weekday != 7)BEGINinsert into #datelist values (@currentdate)endselect @currentdate=dateadd(d, 1, @currentdate)Endselect * from(select q.qdate as qDate, 'FIXED INCOME' as DataRange, count(q.qsid)as SidCount from qpricetruv2005 q, #datelist dwhere d.datecheck = q.qdate and q.qsid > 5000000 and q.qsid <= 890000000 and q.qprice is not null group by q.qdateUNION ALLselect q.qdate as qDate, 'EQUITY' as DataRange, count(q.qsid) as SidCount from qpricetruv2005 q, #datelist dwhere d.datecheck = q.qdate and qsid >= 0 and qsid <= 5000000 and q.qprice is not null group by q.qdate) as overallorder by qdate, datarangeAny 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!!!" |
|
|
|
|
|