Wednesday, March 7, 2012

Function Column

I have a question. I am relatively new to databases, and I have
question that I am not sure of. I have a table consisting of computer
information (name, type, location, etc). One of the columns that I
have is warrantyDate which is of type DateTime and it tells when a
machine goes out of warranty.
I would like to have another column in which gives the days left of
warranty. I would like this to be updated constantly, so any day I
query the table, the proper amount of days left on the warranty of a
machine will be available. Is this possible? If so, where do I start
to look for the answers?
Thanks!You can have:
1) a computed column
2) a view that does the equivalent of 1
3) do the query on the fly
Here's the computed column:
alter table MyTable
add
DaysLeft as datediff (dd, getdate(), warrantyDate)
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
<leshanster@.gmail.com> wrote in message
news:1148824834.873869.236910@.g10g2000cwb.googlegroups.com...
I have a question. I am relatively new to databases, and I have
question that I am not sure of. I have a table consisting of computer
information (name, type, location, etc). One of the columns that I
have is warrantyDate which is of type DateTime and it tells when a
machine goes out of warranty.
I would like to have another column in which gives the days left of
warranty. I would like this to be updated constantly, so any day I
query the table, the proper amount of days left on the warranty of a
machine will be available. Is this possible? If so, where do I start
to look for the answers?
Thanks!|||Thank you so much! That was exactly what I wanted!

No comments:

Post a Comment