Solved

Insert Trigger

Posted on 2009-06-28
2
183 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

690 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