July 13, 2010 at 8:44 am
SELECT min(upvolume),min(downvolume),MAX(upvolume),max(downvolume)
FROM DBVaskVbid WITH (NOLOCK)
WHERE TotalTrades
BETWEEN (SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
AND
(SELECT MAX(TotalTrades)-1000 FROM DBVaskVbid WITH (NOLOCK))
I have a datestamp field registering 7/13/2010 3:38:00 PM and an cumulative ID field
What I am trying to do is select the maximum Totaltrades from the database on todays date only, as yesterdays totaltrades field will start from zero.
I also want the between statement to be Totaltrades(the last incoming record) minus 1000, but I am not getting that through on this statement
Thanks
Neil
July 13, 2010 at 8:54 am
SELECT min(upvolume),min(downvolume),MAX(upvolume),max(downvolume)
FROM DBVaskVbid WITH (NOLOCK)
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK)) -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
A better statement, but how can i link today's date only, or the last record - 1000?
July 13, 2010 at 8:55 am
jon pill (7/13/2010)
SELECT min(upvolume),min(downvolume),MAX(upvolume),max(downvolume)
FROM DBVaskVbid WITH (NOLOCK)
WHERE TotalTrades
BETWEEN (SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
AND
(SELECT MAX(TotalTrades)-1000 FROM DBVaskVbid WITH (NOLOCK))
I have a datestamp field registering 7/13/2010 3:38:00 PM and an cumulative ID field
What I am trying to do is select the maximum Totaltrades from the database on todays date only, as yesterdays totaltrades field will start from zero.
I also want the between statement to be Totaltrades(the last incoming record) minus 1000, but I am not getting that through on this statement
Thanks
Neil
I can't see that your are trying to select the maximum Totaltrades from the database on todays date only. Where the check for today? Which column contains datestamp?
What you mean by Totaltrades(the last incoming record)? Is it Totaltrades value of the last record for the required day or what?
Actually, I would strongly advise you to click the link in my signature. You will find some information which will help you to represent your case/question in a proper and "forum polite" way.
July 13, 2010 at 9:10 am
SELECT
min(upvolume),
min(downvolume),
max(upvolume),
max(downvolume)
FROM
DBVaskVbid WITH (NOLOCK)
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK)) -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
The above code is working, the field TotalTrades is reset to zero every day, so therefore selecting Max total trades wont be the maximum total trades for the current day, so I need to reference todays date to get the real time totaltrades as it cumulates from zero every new day
Thanks
July 13, 2010 at 9:12 am
I dont know how to do the check for today only
July 13, 2010 at 9:16 am
...
click the link in my signature
...
July 13, 2010 at 9:29 am
What is wrong with the post, it is orderly?
July 13, 2010 at 9:33 am
WHERE BarStamp > '7/13/2010'
ok this works to select the current day, now i need to join it
July 14, 2010 at 12:08 am
jon pill (7/13/2010)
What is wrong with the post, it is orderly?
Nothing is wrong if you don't mind either verbal-only answers, swags, or incorrect code. People like to test their code before they post it but don't want to have to guess about the datatypes in the table nor create any test data. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
July 14, 2010 at 3:03 am
SELECT min(upvolume),min(downvolume),Max(upvolume),Max(downvolume)
FROM
(SELECT upvolume,downvolume,TotalTrades from DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/13/2010') as XDtable
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK)) -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
This worked for me
July 14, 2010 at 4:44 am
jon pill (7/14/2010)
SELECT min(upvolume),min(downvolume),Max(upvolume),Max(downvolume)
FROM
(SELECT upvolume,downvolume,TotalTrades from DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/13/2010') as XDtable
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK)) -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK))
This worked for me
Jon, what if a value of TotalTrades is higher from yesterday than any for today?
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 7:58 am
SELECT min(upvolume),min(downvolume),min(upvolume),min(downvolume)
FROM
(SELECT upvolume,downvolume,TotalTrades from DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010') as XDtable
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010') -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010')
This is my solution, is there a better way to write this, I am sure I have to many "where BarStamp >= '7/14/2010') -1000" statements
July 14, 2010 at 8:10 am
I like noodles some times, but usually I have them cooked not coded...:-D
Read about using CTE in SQLServer. Also, introducing variable to hold MAX(TotalTrades) will make your code look better and perform faster
July 14, 2010 at 8:23 am
jon pill (7/14/2010)
SELECT min(upvolume),min(downvolume),min(upvolume),min(downvolume)
FROM
(SELECT upvolume,downvolume,TotalTrades from DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010') as XDtable
WHERE TotalTrades
BETWEEN
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010') -1000
AND
(SELECT MAX(TotalTrades)FROM DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010')
This is my solution, is there a better way to write this, I am sure I have to many "where BarStamp >= '7/14/2010') -1000" statements
There's almost certainly a better way of writing this, but not without a better way of going about it. Write the query step by step, starting with the filter. You want to select a set of data from your source table to work with. Write the query to do that, then extend it to incorporate the aggregate afterwards. Most of us are still scratching our heads trying to figure out the filter - but that's probably because you are, too.
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 8:51 am
SELECT upvolume as UPVol,
downvolume as DNVol,
TotalTrades as TTrades,
Barstamp as BStamp
from DBVaskVbid WITH (NOLOCK) where BarStamp >= '7/14/2010'
46411473972010-07-14 13:08:00.000
46411473972010-07-14 13:08:00.000
46411473972010-07-14 13:08:00.000
46411473972010-07-14 13:08:00.000
46411473972010-07-14 13:08:00.000
46411973982010-07-14 13:08:00.000
46411973982010-07-14 13:08:00.000
46411973982010-07-14 13:08:00.000
46511984002010-07-14 13:08:00.000
47611984022010-07-14 13:08:00.000
47611984022010-07-14 13:08:00.000
47611984022010-07-14 13:08:00.000
This is the filter, it works correctly
Now all I want is the Min and Max from the rows of that table.
But I am stepping back into the database to find the min max of upvolume and downvolume
Viewing 15 posts - 1 through 15 (of 46 total)
You must be logged in to reply to this topic. Login to reply