July 14, 2010 at 9:19 am
Jon,
The last query you posted looks very wrong (or crap, in Australian :-D).
For one or another reason everyone here is struggling to understand your filtering requirements.
I am, again, strongly suggesting you to read the link in my signature.
July 14, 2010 at 9:36 am
you right that cant be it either
July 14, 2010 at 9:39 am
jon pill (7/14/2010)
you right that cant be it either
Describe it in words. Be nice!
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 14, 2010 at 9:46 am
I have data that I want to find the Min and Max off, for 2 fields
Upvolume and DownVolume
Every day the Totaltrades field starts at zero and cumulates throughout the day, there will be more than 1 day.
I want to find the maximum totaltrades and the maximum totaltrades less 1000
to then find
Then find the min and max for the upvolume and downvolume of the above filter
That is all
July 14, 2010 at 9:51 am
jon pill (7/14/2010)
I have data that I want to find the Min and Max off, for 2 fieldsUpvolume and DownVolume
Every day the Totaltrades field starts at zero and cumulates throughout the day, there will be more than 1 day.
I want to find the maximum totaltrades and the maximum totaltrades less 1000
to then find
Then find the min and max for the upvolume and downvolume of the above filter
That is all
How about "The last 1000 totaltrades numbers for today - there may be gaps and dupes in the totaltrades sequence" - how does this fit?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 14, 2010 at 10:05 am
Chris Morris-439714 (7/14/2010)
jon pill (7/14/2010)
I have data that I want to find the Min and Max off, for 2 fieldsUpvolume and DownVolume
Every day the Totaltrades field starts at zero and cumulates throughout the day, there will be more than 1 day.
I want to find the maximum totaltrades and the maximum totaltrades less 1000
to then find
Then find the min and max for the upvolume and downvolume of the above filter
That is all
How about "The last 1000 totaltrades numbers for today - there may be gaps and dupes in the totaltrades sequence" - how does this fit?
Chris, until OP will provide case setup srcipt with good sample of data representing real situation and expected results it will be hard to help help him (3 pages of the thread is a good avidence of that...)
July 14, 2010 at 10:07 am
There will be gaps but it matters little, i only need to get the data the same way every time
The same with duplicates, it wont affect the hi and low
Many thanks
July 14, 2010 at 10:18 am
jon pill (7/14/2010)
There will be gaps but it matters little, i only need to get the data the same way every timeThe same with duplicates, it wont affect the hi and low
Many thanks
Of course it will, which is why folks are hitting you hard to get a better definition of what you mean by totaltrades-1000. It's still ambiguous. My best guess right now is:
Find the highest figure of totaltrades for today
Subtract 1000 from that figure.
If your requirement is this simple then say so, because then your filter becomes "where the rows are from today and the totaltrades number is higher than x", where x = totaltrades-1000.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 14, 2010 at 10:21 am
Find the highest figure of totaltrades for today
Subtract 1000 from that figure.
yes it is that simple
very sorry i can see me error now
July 14, 2010 at 10:34 am
SELECT upvolume,downvolume,TotalTrades
INTO #TodayRecords
FROM DBVaskVbid WITH (NOLOCK) -- are you fully awre of what this hint does?
WHERE BarStamp >= '7/14/2010'
-- do you have huge vlume of records per day, than the following index might help
CREATE INDEX idx_TodayRecords ON #TodayRecords(TotalTrades)
DECLARE @MinTtlTrades INT
SELECT @MinTtlTrades = MAX(TotalTrades) - 1000 FROM #TodayRecords
SELECT MAX(upvolume), MAX(downvolume), MIN(upvolume), MIN(downvolume)
FROM #TodayRecords
WHERE TotalTrades > @MinTtlTrades
July 14, 2010 at 11:22 am
Eugene Elutin (7/14/2010)
SELECT upvolume,downvolume,TotalTrades
INTO #TodayRecords
FROM DBVaskVbid WITH (NOLOCK) -- are you fully awre of what this hint does?
WHERE BarStamp >= '7/14/2010'
-- do you have huge vlume of records per day, than the following index might help
CREATE INDEX idx_TodayRecords ON #TodayRecords(TotalTrades)
DECLARE @MinTtlTrades INT
SELECT @MinTtlTrades = MAX(TotalTrades) - 1000 FROM #TodayRecords
SELECT MAX(upvolume), MAX(downvolume), MIN(upvolume), MIN(downvolume)
FROM #TodayRecords
WHERE TotalTrades > @MinTtlTrades
One thing that keeps jumping out at me is the phrase "for today" (paraphrased most likely).
Part of the where clause should probably look like this:
WHERE BarStamp >= dateadd(dd, datediff(dd, cast('1900-01-01' as datetime), getdate()), cast('1900-01-01' as datetime)
July 14, 2010 at 11:51 am
Thank you for that Lynn
I was sending the SQL statement from another application, but I will add that to my list of statements in SQL
July 15, 2010 at 5:46 am
Really sorry about this,
But I can only run the query once
Msg 2714, Level 16, State 6, Line 1
There is already an object named '#TodayRecords' in the database.
I would like to run this many times a day, how can I clear the object?
July 15, 2010 at 6:05 am
drop table #TodayRecords
Is this the fastest way, i will have over a 100 lines and will be calling sql every 500ms?
Viewing 15 posts - 16 through 30 (of 46 total)
You must be logged in to reply to this topic. Login to reply