Solved

Insert Trigger

Posted on 2009-06-28
2
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

763 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