Solved

sql trigger after update not working in one section

Posted on 2014-09-05
2
175 Views
Last Modified: 2014-09-06
I am having problems with this portion:

--allow a valid NMSR Date to be inserted
if (@srdate is not null) and (@srcompletedate is null) and (@nmsrdate_delete is null) and (@nmsrdate is not null) and (@nmsrdate >= @srdate and @nmsrdate <= @currentdate)
      begin
            
            update [Service Database] set [NMSR_Date] = @nmsrdate_delete where [Service Report No] = @srnum
    end

When I try to change the current NULL value for the NMSR_Date column for that record to any date, the value return back to NULL when it should have taken the new value for the date.

Please help.  Thanks.

Sanjay
script.txt
NullNMSRDateTrigger-UPDATE-ServiceDataba
0
Comment
Question by:sxxgupta
2 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
Comment Utility
Look at your condition again. It only runs if @nmsrdate_delete is null (line 3 of the listing below). And, if that is so, it sets NMSR_Date to @nmsrdate_delete (which is what it was before the trigger was activated!)

hth

Mike



	if 	(@srdate is not null) 
		and (@srcompletedate is null) 
		and (@nmsrdate_delete is null) 
		and (@nmsrdate is not null) 
		and (@nmsrdate >= @srdate and @nmsrdate <= @currentdate)
	begin
		--raiserror (50009,11,1) with nowait
		update [Service Database] 
			set [NMSR_Date] = @nmsrdate_delete 
			where [Service Report No] = @srnum
    end

Open in new window

0
 

Author Closing Comment

by:sxxgupta
Comment Utility
Yup.  I noticed that.  Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now