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
 Problems to create the values of a new column

Author  Topic 

MGarriga
Starting Member

5 Posts

Posted - 2010-10-21 : 11:25:02

I have the following table:
PropertyID , YearSale , SalePrice , ImprYr, ImprValue
1 , , , 1979 , 20500
1 , , , 1981 , 48600
1 , , , 1982 , 37000
1 , 2001 , 0 , ,
1 , 2002 , 860000 , ,
1 , , , 2003, 77370
1 , , , 2004, 9090
1 , 2006 , 1480000 , ,

And I want to create a query that would add a new column, let’s call it PropertyValue,that would add to the SalePrice the Value of the improvements done after the sale, but the next sale will reset the property value back to saleprice, and it would ignore any improvements done before a sale, so that it will look like this:


PropertyID,YearSale,SalePrice,ImprYr, ImprValue , propertyValue
1 , , , 1979 , 20500 , 0
1 , , , 1981 , 48600 , 0
1 , , , 1982 , 37000 , 0
1 , 2001 , 0 , , , 0
1 , 2002 , 860000 , , , 860000
1 , , , 2003 , 77370 , 937700
1 , , , 2004 , 9090 , 946460
1 , 2006 , 1480000, , , 1480000

I am completely lost on how to do this. Any ideas?
Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-23 : 02:11:37
sorry your rules are not clear. can you explain how you got the 937700,946460 etc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -