Solved

sql trigger after update not working in one section

Posted on 2014-09-05
2
178 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
ID: 40307429
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
ID: 40307526
Yup.  I noticed that.  Thanks.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine log file requirements 7 35
triggered use of sp_send_dbmail failure 2 23
SQL Server Question 5 28
What namespace do I need to import? 2 8
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

896 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

19 Experts available now in Live!

Get 1:1 Help Now