Solved

sql trigger after update not working in one section

Posted on 2014-09-05
2
186 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
[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 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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