We help IT Professionals succeed at work.
Get Started

Create SQL Trigger that denies INSERT

Last Modified: 2012-05-09

I have a small table which is filled with timing data. Please see picture for details.

The values come from an application installed on all computers. It logs certain times (logon-time, overall runtime etc...) but sometimes the values are not correct, so I need to deny writing them to the db.
I. e. the difference between EndTime and LogonTime should not exceed 40 Minutes. Any higher value is incorrect and should not be written to the db.

Note: The column TimeLogonEnd is an nvarchar-type so it is easier to calculate the difference by using EndTime - LogonTime.

The sample contains two rows. The first one is ok, the second one exceeds 40 Minutes (EndTime - LogonTime) and should not be written to db.

I thought of writing a trigger that denies the insert, but I don't have the time to search google all day on how to do it, so I'm asking for help here.

Thanks and regards
Watch Question
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
This problem has been solved!
Unlock 2 Answers and 18 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE