Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My Trigger isn't triggering

Status
Not open for further replies.

williamkremer

Programmer
Oct 27, 2005
61
When the sales rep updates a record with the value 'CT' we want to insert a date in another table (cast as Varchar, cuz it's a varchar field) This was the trigger I wrote but it ain't triggering!! (Key3 is not updating with the Date)
***********************************
USE SalesCrm_06
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'TrgLastCont' AND type = 'TR')
DROP TRIGGER TrgLastCont
GO
CREATE TRIGGER TrgLastCont ON Conthist
FOR Update AS
declare @accountno varchar (20)
declare @ondate varchar (11)
declare @resultcode varchar(3)

SELECT top 1 @ondate = cast (conthist.ondate as varchar(11)),
@accountno = conthist.accountno, @resultcode = conthist.resultcode
from conthist where (conthist.ondate <> '' or conthist.ondate is not null)
and conthist.resultcode = 'CT' and conthist.ondate = getdate()
order by conthist.ondate desc

if @resultcode = 'CT'
Begin
update Contact1 set Key3 = @ondate
where contact1.accountno = @accountno
end

Best regards,
Bill
 
Ah, yes. So I could say -- where month(ondate) = month(getdate()) and day(ondate) = day(getdate()) and year(ondate) = year(getdate()), but is there an easier way to do this. It seems very wordy.
Thanks Denis

Best regards,
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top