|
Posted by Erland Sommarskog on 09/27/86 11:52
lluum@yahoo.com (lluum@yahoo.com) writes:
> Here are my specific questions:
> 1. Should I define the column SMA_50 as a Computed Column and use a
> user defined function to perform the computation, or should I use other
> approaches (such as triggers stored procedures)?
Trigger or stored procedure is what I would pick. A computed column
that includes a UDF with data access is likely to give poor performance.
> 2. For each trading day, how can I select the ClosePrice of the last
> fifty trading days.
> Note that trading dates are not consecutive, weekends and holidays are
> NOT trading days. It appears to be easy, but as an occasional user of
> DB, I do not have an immediate solution.
CREATE TABLE tradingdays (date datetime NOT NULL,
dayno int NOT NULL,
CONSTRAINT pk_tradingdays PRIMARY KEY (date),
CONSTRAINT u_tradingdays UNIQUE (dayno))
That is a table that maps a day to a number. The rest is easy.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|