Solved

Insert Trigger

Posted on 2009-06-28
2
160 Views
Last Modified: 2012-05-07
I cannot touch the inline SQL in an application - but need to check a value on insert and perform a case statement against a value - basically an ISNULL around one of the values - how do I check a value on INSERT and if = X then...
0
Comment
Question by:tbaseflug
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 24731786
create trigger my_Trigger on myTable for insert as

update t1
set colToChange= isnull(T2.colToChange, default_value)
from myTable t1
 join inserted t2 on t1.id = t2.id
0
 
LVL 15

Expert Comment

by:rob_farley
ID: 24733331
Depending on more details about the problem, I'd try to work it into a computed column instead of a trigger. Triggers can be notorious for locking, etc.

Are you saying that you want to change a particular value to record when a value was changed in a certain way, or just that you want a particular column to reflect the result of an ISNULL? If it's the latter, then a computed column is definitely the way to go.

Rob
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question