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.
| Author |
Topic |
|
lamchau12
Starting Member
2 Posts |
Posted - 2010-03-18 : 08:45:22
|
| Hi all,I have three tables : A(id, columnA); B(id, columnB) and C(id, columnC)i want to use computed for columnC with following formula : columnC = A.columnA + B.columnBHow could i do that? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-18 : 12:47:13
|
| [code]UPDATE cSET c.columnC=COALESCE(a.columnA,'') + COALESCE(b.columnB,'')FROM C cJOIN B bOON b.id=c.idJOIN A aON a.ID=b.ID[/code]if columns are numeric replace '' with 0------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lamchau12
Starting Member
2 Posts |
Posted - 2010-03-19 : 04:18:16
|
| Thank you for your support. But i meant using computed attribute of sql server 2008Ex : CREATE TABLE [dbo].[C]( [id] [nvarchar](50) NULL, [column3] AS ([ColumnA]+[ColumnB])) How could i use computed attribute to calculate value of Column3 automatically? I'm already using trigger in this case. But my data is too large. Therefore i need to use computed attribute in this case. |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-19 : 04:38:55
|
quote: Originally posted by lamchau12 Thank you for your support. But i meant using computed attribute of sql server 2008Ex : CREATE TABLE [dbo].[C]( [id] [nvarchar](50) NULL, [column3] AS ([ColumnA]+[ColumnB])) How could i use computed attribute to calculate value of Column3 automatically? I'm already using trigger in this case. But my data is too large. Therefore i need to use computed attribute in this case.
Are you trying for this?http://www.mssqltips.com/tip.asp?tip=1682 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-19 : 04:54:59
|
| Another option is to have a viewCreate view your_viewasselect t1.cola,t2.colb,t1.cola+t2.colb as colc from A as t1 inner join B as t2 on t1.id=t2.idMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|