Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table in the Sql-server 2005, i want to perform math operation on two column(ex addition,multiplication) and save the result in the 3 rd column.
is it possible to do with stored procedure.
Posted

1 solution

Yes:
SQL
USE [Testing]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [proc_AddEmUp] 
AS
UPDATE myTable SET sumColumn=firstColumn+SecondColumn
 
Share this answer
 
Comments
shrikant.kudlur 6-Mar-12 23:48pm    
Thanks for the answer
i have one more question
i am executing two update statement, i don't want to execute second update statement if the first update statement fails.

and i m very new to stored procedure can any one suggest me good book or web site.

thanks in advance..
OriginalGriff 7-Mar-12 4:18am    
You could check the @@ERROR code, and only do the second UPDATE if it is zero.
Or, you could use a TRANSACTION and ROLLBACK if either errors - which would be preferable as it leaves your database in a better, more "known" state.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900