Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DERIVED FIELDS

Status
Not open for further replies.

critzos

Programmer
Mar 21, 2002
12
0
0
US
How does one create a derived field (column) in a table? I.E. The table has 4 columns (for example) and the 4th column should be the sum of the other 3. Also, can one make a field's (columns) property such that nothing can be entered into the field? Thanks in advance.
 
If you are using SQL 2000, read in SQL Books Online about "Computed Columns." Earlier versions did not have computed columns. You can always return a computed or derived value in a query in any version of SQL Server.

Select Col1, Col2, Col3, Col4=Col1+Col2+Col3
From YourTable Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Hi,
While creating a table itself you can create the computed field. Suppose you want to create a column as sum of two already delcared columns, you can create as follows

create table test
(a int,
b int,
c as a+b)

Here the column C is stored the date vartually in the table , it cannot appear physically in the table.
For more details read BOL, topic is CREATE TABLE <computed_cloumn>

Madhu.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top