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
 Formula for Computed Column

Author  Topic 

DianeJ
Starting Member

6 Posts

Posted - 2007-01-17 : 18:16:56
I have downloaded the SQL Server Books online and found the section on Computed columns. In my small banking program I have columns named Deposit/Withdrawel and Balance. If I am reading this right I need to set the Computed Column Specification of my Balance Column in order to perform the calculation. My problem now is that I have no idea how to word the formula and other than telling me what a formula is the SQL Server Books online is no help whatsoever, so any help would be awesome.

If i've misunderstood what I am meant to do somebody please please tell me. Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-17 : 18:24:52
ALTER TABLE <YourTableNameHere>
ADD <YourColumnNameHere> AS (Deposit - Withdrawal)
GO


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

DianeJ
Starting Member

6 Posts

Posted - 2007-01-17 : 18:50:39
Correct me if im doing this wrong because I am getting a message that says "Error validating the formula for column 'Balance'" when I do this.

I have called up my 'TransactionDetails' table, gone into the properties for the 'Balance' column and entered the following into the - Computed Column Specification - Formula property.

ALTER TABLE TransactionDetails ADD Balance As (Deposit - Withdrawel) GO

This is exactly what I have typed (it all has to be typed on one line here)

Sorry to be so dense about this, and I really appreciate your help
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-18 : 01:41:26
This is the code you have to run in SSMS or Query Analyser.
If you are editing the properties directly, you onyl have to write the actual formula

Deposit - Withdrawel

in the property window.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -