Groups | Blog | Home
all groups > sql server (alternate) > april 2004 >

sql server (alternate) : Direct access to records via timestamp



chrisandkayenolan NO[at]SPAM yahoo.co.uk
4/14/2004 3:02:55 AM
Are you using MSSQL7 or 2000?

[quoted text, click to view]
news.inspire.net.nz
4/14/2004 9:20:52 AM
Let us consider the example of a stock system. Suppose that in each
transaction, cumulative totals of sales are kept. Now to find the
cumulative sales at any time a composite index of stockcode and transaction
timestamp could be stored. To access the index a composite key of stock
code and timestamp (for the time at which we want to know the stock level)
could be used to access the index. In all likelyhood there was no
transaction at exactly that time. So we need to back up the index to the
previous record. If there is no previous record, or the previous record has
a different stock code then we know that the cumulative sales at that time
is zero.

How do I do this with MS Sql server?

Looking forward to your replies.

Tony

Simon Hayes
4/14/2004 4:32:29 PM

[quoted text, click to view]

I don't really follow your narrative - you may want to consider posting
sample DDL to illustrate your issue. Without more information I don't know
exactly what you're looking for, but the easiest way to find cumulative
sales/shipments for a given period of time would probably be to get the sum
of all sales/shipments quantities between two points in time:

SELECT SUM(QuantityShipped)
FROM dbo.Orders
WHERE PartNumber = 1234
AND ShippedDate BETWEEN '20040101' AND '20040331'

This is an artificially simple example of course, and may not be what you're
looking for at all - I'm just guessing.

Simon

news.inspire.net.nz
4/15/2004 2:45:59 PM
MSDE - whatever that is.

[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.647 / Virus Database: 414 - Release Date: 29/03/2004

news.inspire.net.nz
4/15/2004 2:58:37 PM
The point of the narrative is that this way there is no reason to sum the
data, only to retrieve the required records and do a subtraction. I will
illustrate with an example. Let us assume only one product, product number
1:


transid ProductId TimeStamp Qty CumQty
1 1 2004-01-01,10:18:43 6 6
2 1 2004-01-01,15:12:04 4 10
3 1 2004-01-02,08:17:22 3 13
4 1 2004-01-04,11:18:08 7 20
5 1 2004-01-12:13:12:22 7 27

To find the sales between 2004-01-02,01:00:00 and 2004-01-03,01:00:00
Sales at 2004-01-03,01:00:00 stood at 13 (transid 3)
Sales at 2004-01-02,01:00:00 stood at 10 (transid 2)
Sales over period = 13-10 = 3

Imagine how much faster this is instead of adding up all the records for a
year!

Hope this helps



[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.647 / Virus Database: 414 - Release Date: 29/03/2004

AddThis Social Bookmark Button