Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic field value

Status
Not open for further replies.

mattpont

Programmer
Jan 31, 2003
66
0
0
GB
In my SQL Server database, I want a new field in my table called something like 'UPDATED'.

I want this to be defaulted to FALSE. If fields x, y or z are set to TRUE then I want the value of UPDATED to be changed to TRUE as well. And then, if x, y and z are ALL changed to FALSE, then the value of UPDATED be set back to FALSE again.

Is this possible? If so, can someone show me how, or point me in the right direction please?

Thanks a lot.
 
You might try a computed column.
BOL said:
This example illustrates the use of an expression ((low + high)/2) for calculating the myavg computed column.

CREATE TABLE mytable
(
low int,
high int,
myavg AS (low + high)/2
)
but I don't know if you can use an IF as part of a computed column. You might be best creating a trigger or two (one for inserting and one for updating).

-SQLBill


Posting advice: FAQ481-4875
 
Ok, thanks, I thought that Triggers may be a solution.

I've been googling them for the past hour.

Does anyone have experience of SQL triggers and could show me what I need to do in order to get this to work?
 
Instead of Googling them, use the Books OnLine that comes with SQL Server. Use the Index tab and enter CREATE TRIGGER. You will find explanations and examples.

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top