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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert into col value by adding two other columns

Author  Topic 

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-09 : 11:37:35


Table A
ColID ColA ColB ColC

ColID is primary key column. ColA and ColB are also integer.

If I would like to do some calculation. Eg (ColA * 2 + ColB), and then put into ColC.
Any way to do it?



be a hardworking people!!

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-09 : 11:43:59
To be more specfic, how to construct a insert query to do so ?
or any othe options and they difference/

be a hardworking people!!
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-08-09 : 11:44:20
UPDATE [Table A]
SET ColC = ColA * 2 + ColB

Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-08-09 : 11:44:35
[code]UPDATE [Table A]
SET ColC = (ColA * 2) + ColB[/code]
Or is there more to it than that?

Mark
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-08-09 : 11:46:03
If values for ColA and ColB have not already been populated for the table:

INSERT INTO [Table A]
SELECT ColID, ColA, ColB, ColA*2 + ColB
FROM ...
Go to Top of Page

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-09 : 12:16:02
I see, Thx!

be a hardworking people!!
Go to Top of Page
   

- Advertisement -