question

Johnny9730 avatar image
Johnny9730 asked

Automatically update interest cost each time database opened

I have an SQl datatabase that has an "Interest" column that shows the opportunity interest cost incurred on an investment. That is, the interest that would have been received if the amount invested had been invested in a term deposit. As each day passes, the opportunity cost increases. I have a C# front end that gets all the data into the database. My problem is that each time I open the database in C# gridview I want the opportunity interest cost to automatically update - that is to increase the interest cost to reflect the additional time that the investment has been made. I a novice in and am looking for some pointers as to an approach, book or method or some SQL terms that I should look at for coming up with a solution.
updatetable
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Wimbush avatar image
David Wimbush answered
You can include a calculated column in your query. So you could do something like this: select Name , DateAcquired , Value , InterestAPR , Value * ((InterestAPR / 365) * datediff(day, DateAcquired, getdate()) as OpportunityInterestCost from dbo.Asset order by DateAcquired , Name;
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Johnny9730 avatar image
Johnny9730 answered
Many thanks for your reply that worked great.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.