This requires the Group by since the RecordID's are out of order and the data is synced by Record ID.
The Error is
"Msg 8114, Level 16, State 5, Line 15
Error converting data type nvarchar to numeric."
This Select works just fine but having trouble making it into an Update.
See attachment for sample data.
DougP
The Error is
"Msg 8114, Level 16, State 5, Line 15
Error converting data type nvarchar to numeric."
Code:
UPDATE [dbo].[HistData]
SET [TCKR%] = CAST(Ticker as decimal(9,6))
FROM [dbo].[HistData]
Where Exists (Select E.RecordID as TheRecordID,
(L.Stock_Close - E.Stock_Close)/L.Stock_Close as Ticker
from HistData as L
inner join HistData AS E on L.RecordID = E.RecordID + 1
Where L.RecordID= L.RecordID
Group by E.RecordID,L.Stock_Close,E.Stock_Close)
This Select works just fine but having trouble making it into an Update.
Code:
Select E.RecordID as TheRecordID, L.Stock_Close, E.Stock_Close,
(L.Stock_Close - E.Stock_Close)/L.Stock_Close
from HistData as L
inner join HistData AS E on L.RecordID = E.RecordID + 1
Where L.RecordID= L.RecordID
Group by E.RecordID,L.Stock_Close,E.Stock_Close
See attachment for sample data.
DougP