Solved

sql trigger after update not working in one section

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Sub-Query Help 22 62
SQL Help 27 45
Query Syntax 17 36
why sql server only update some statistics in the database ? 3 22
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.
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

778 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