September 30, 2010 at 3:55 am
Hi,
Could some one tell me if it is possible to add an extra column to a view that contains a calculated value.
I know how to do it to a table but need to know if it is possible to do in on a View.
Many Thanks
September 30, 2010 at 4:13 am
yes you can, the syntax is the same as when you select something based on other data, just make sure the column name is assigned;
ColumnName = [calculation,case statement, formula,etc]
or
[calculation,case statement, formula,etc] AS ColumnName
examples:
CREATE VIEW vw_example
AS
SELECT s.*,
CASE
WHEN s.status = 0
THEN 'Open'
WHEN s.status = 2
THEN 'Closed'
ELSE 'Pending'
END AS CurrentStatus ,
MyFormula = s.Paycheck - (s.Taxes + s.Insurance) + s.Bonus,
s.Paycheck - (s.Taxes + s.Insurance) + s.Bonus As SameFormula
FROM Example s
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply