You are here: Re: a newbie question on derived/computed column « MsSQL Server « IT news, forums, messages
Re: a newbie question on derived/computed column

Posted by Erland Sommarskog on 09/29/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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация