Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
chris #1
Update field with other fields data minus one day
Hi
I really don't know how to go about this in a relational database.
There is data thats downloaded from the net everyday. The data includes a
opening price of stock. What I need in the database is to update the today's
opening price with yesterday's closing price.
eg
Instrument, Date, Opening price, Closing Price
ABI 20021028 <Null> 4499
ABI 20021029 <Null> 4410
The opening price for 20021029 should be 4499
Any ideas
Many thanks
Chris
chris Guest
-
Calculating field - minus??
Hi, OK I have a form created in Acrobat 8 Pro with all the fields set as they should be and some fields calculate the value of others by (plus +)... -
Comparing current field data with last entry for field
Hi. I have a form that is inserting sales data on a daily basis. I have a field named "RoundTOTAL" which is the total sales for the day rounded to... -
Illustrator CS minus back and minus front
How come there is a minus back option on the Pathfinder Palette, but no Minus Front?????? -
Automatically update a field when another field is entered.
I am trying to create a field in a form that will be automatically populated when another field is entered. I have facility names with related ID... -
Autonumber field does not update immediately after entering data
The autonumber field does not update immediately upon entering data into a field. For instance, I can enter part of a Date in a date field or... -
Jacco Schalkwijk #2
Re: Update field with other fields data minus one day
Assuming that there is a Primary Key on (Instrument, date)
UPDATE myTable
SET OpeningPrice = (SELECT ClosingPrice FROM MyTable t2
WHERE t2.date = myTable.date -1 AND t2.Instrument = myTable.Instrument)
Or if you don't have prices for everyday, get the price for the last day for
which there is one:
UPDATE myTable
SET OpeningPrice = (SELECT TOP 1 ClosingPrice FROM MyTable t2
WHERE t2.date < myTable.date AND t2.Instrument = myTable.Instrument
ORDER BY t2.date DESC)
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"chris" <chris@nutcracker.co.za> wrote in message
news:O57rE#tRDHA.3700@tk2msftngp13.phx.gbl...today's> Hi
>
> I really don't know how to go about this in a relational database.
>
> There is data thats downloaded from the net everyday. The data includes a
> opening price of stock. What I need in the database is to update the> opening price with yesterday's closing price.
>
> eg
> Instrument, Date, Opening price, Closing Price
> ABI 20021028 <Null> 4499
> ABI 20021029 <Null> 4410
>
> The opening price for 20021029 should be 4499
>
> Any ideas
> Many thanks
> Chris
>
>
Jacco Schalkwijk Guest
-
Stefan Gustafsson #3
Re: Update field with other fields data minus one day
UPDATE StockTable
SET OpeningPrice = (
SELECT TOP 1 ClosingPrice
FROM StockTable S
WHERE S.Instrument = StockTable.Instrument
AND S.Date < StockTable.Date
ORDER BY S.Date DESC)
"chris" <chris@nutcracker.co.za> wrote in message
news:O57rE#tRDHA.3700@tk2msftngp13.phx.gbl...today's> Hi
>
> I really don't know how to go about this in a relational database.
>
> There is data thats downloaded from the net everyday. The data includes a
> opening price of stock. What I need in the database is to update the> opening price with yesterday's closing price.
>
> eg
> Instrument, Date, Opening price, Closing Price
> ABI 20021028 <Null> 4499
> ABI 20021029 <Null> 4410
>
> The opening price for 20021029 should be 4499
>
> Any ideas
> Many thanks
> Chris
>
>
Stefan Gustafsson Guest



Reply With Quote

