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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 calculated column errors [Resolved]

Author  Topic 

lappin
Posting Yak Master

182 Posts

Posted - 2011-04-12 : 10:49:53
Hi, I've recently modified a column to be a calculated column. Is it possible to set sql server to ignore attempts to update this field rather than returning an error. I have modified applications which attempt to do this - but am worried I might have missed one, and don't want it crashing an update.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-04-12 : 10:59:58
You could create a trigger that ignores any attempted update to the computed column.
Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 2011-04-12 : 11:13:02
quote:
Originally posted by RickD

You could create a trigger that ignores any attempted update to the computed column.



Could you give an example?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-04-12 : 11:57:04
Enough pseudo code to give you an idea..

CREATE TRIGGER TR_Whatever
INSTEAD OF INSERT , UPDATE
AS
...Check if insert or update here by querying the inserted and deleted tables...
IF @var = 'U' --This is set from the query above
IF UPDATE(CalcField)
IGNORE
ELSEIF UPDATE(OtherFields)
UPDATE

IF @var = 'I'
INSERT
Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 2011-04-15 : 11:13:55
Thanks Rick.
Go to Top of Page
   

- Advertisement -