Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 derived attribute column

Author  Topic 

chobes
Starting Member

6 Posts

Posted - 2007-04-04 : 05:00:35
Hello, first time here, first time messing with SQL.

When creating a table in SQLServer2005 can you specify a column to be for a derived attribute. example a column monthlysalary and create a column that is a derived attribute - yearly salary. Is this done when creating the table and how is the syntax ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-04 : 05:03:17
You can put the result of a function in the computed column. The function can accept parameters too, such as employeeid and year in your case.



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-04 : 05:40:59
Also note that you can derive that in your select statement without derived column


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chobes
Starting Member

6 Posts

Posted - 2007-04-04 : 14:17:58
Thank you. but since i am days new to SQL,, I need a little syntax. my two columns are date and dayofthe week.

I simply wnat to create a column that will be a concatenation of these two columns. (So if the data entered in the columns is 4/20/07 and Tuesday. Then the column I am trying to create would hold- 4/20/07 Tuesday.

I simply want to know how i set up that column during creation of my table.

Gracias.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-04 : 14:24:45
alter table table1
add NewColumn = CONVERT(VARCHAR, DateCol, 1) + ' ' + DATENAME(WEEKDAY, DateCol)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chobes
Starting Member

6 Posts

Posted - 2007-04-04 : 15:06:56
Thank you!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-04 : 15:09:20
Have a look at the PERSISTED keyword. You might benefit a lot from that!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-04 : 23:59:26
quote:
Originally posted by chobes

Thank you. but since i am days new to SQL,, I need a little syntax. my two columns are date and dayofthe week.

I simply wnat to create a column that will be a concatenation of these two columns. (So if the data entered in the columns is 4/20/07 and Tuesday. Then the column I am trying to create would hold- 4/20/07 Tuesday.

I simply want to know how i set up that column during creation of my table.

Gracias.


1 If you want to show them in front end, do it there
2 There is no need of having seperate solumn. In any case you need it only in select statement

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -