| Author |
Topic |
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-09 : 12:26:31
|
| Good Morning,I need to develop a trigger to do the following:An alternative could be a trigger on ALTA_Staging..Title_LastDocumentChangeDateEvery time a record is added or changed, check the DTI_SHORT_LEGAL_DISPLY_TEXT field in the matching DB_TITLE record.If it contains a single semi-colon (i.e. LIKE '%;%' AND NOT LIKE '%;%;%' then get the plan number which is the part before the ‘;’Then, update titledatareplicationdatetime..titledatadatetime with getdate() where the titlereferencenumber = plan number + CSHere is what I have so far...but I don't know if this is right:Update TitleDataReplicationDateTime set TitleDataReceiveDateTime=getdate() from Inserted I inner join DB_Title T on I.TitleReferenceNumber=T.TitleReferenceNumber where T.DTI_SHORT_LEGAL_DISPLY_TEXT like '%;%' AND NOT LIKE '%;%;%' and I.TitleReferenceNumber in (Not sure what to put in here)Please help!!! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 12:34:07
|
something likeCREATE TRIGGER YourTriggerON ALTA_Staging..Title_LastDocumentChangeDateAFTER INSERT,UPDATE ASBEGINUpdate tsett.TitleDataReceiveDateTime=getdate()from TitleDataReplicationDateTime tJOIN Inserted I ON I.TitleReferenceNumber=t.plannumber + t.CSinner join DB_Title tlon I.TitleReferenceNumber=tl.TitleReferenceNumberwhere LEN(tl.DTI_SHORT_LEGAL_DISPLY_TEXT )-LEN(REPLACE(tl.DTI_SHORT_LEGAL_DISPLY_TEXT,';',''))=1END |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-09 : 12:39:48
|
| That's helpful. Thanks.One clarification though. There is no t.plannumber. I have to strip that off from DTI_SHORT_LEGAL_DISPLY_TEXT where the part before the ; is the plan number. From there, I need to use that plannumber + 'CS' to find the record in TitleDataReplicationDateTime to update. Can you help? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 12:44:42
|
| [code]CREATE TRIGGER YourTriggerON ALTA_Staging..Title_LastDocumentChangeDateAFTER INSERT,UPDATE ASBEGINUpdate tsett.TitleDataReceiveDateTime=getdate()from TitleDataReplicationDateTime tJOIN Inserted I ON I.TitleReferenceNumber=LEFT(tl.DTI_SHORT_LEGAL_DISPLY_TEXT,CHARINDEX(';',tl.DTI_SHORT_LEGAL_DISPLY_TEXT)-1) + 'CS'inner join DB_Title tlon I.TitleReferenceNumber=tl.TitleReferenceNumberwhere LEN(tl.DTI_SHORT_LEGAL_DISPLY_TEXT )-LEN(REPLACE(tl.DTI_SHORT_LEGAL_DISPLY_TEXT,';',''))=1END[/code] |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-09 : 14:45:28
|
| I get these errors:Msg 4104, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 17The multi-part identifier "tl.DTI_SHORT_LEGAL_DISPLY_TEXT" could not be bound.Msg 4104, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 17The multi-part identifier "tl.DTI_SHORT_LEGAL_DISPLY_TEXT" could not be bound.Msg 207, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 24Invalid column name 'TitleReferenceNumber'.Any thoughts? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 02:33:34
|
| Does the above fields exist in DB_Title table? else replace alias tl with approprite alias |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-10 : 09:48:36
|
| I replaced tl.TitleReferenceNumber with the actual column name in db_title. That fixed that problem. I'm still getting the error on:Msg 4104, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 17The multi-part identifier "tl.DTI_SHORT_LEGAL_DISPLY_TEXT" could not be bound.That field is the right name. Is there anything else that could be causing this error? |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-10 : 10:10:43
|
| I had to change it to this to get it to compile:Update tsett.TitleDataReceiveDateTime=getdate()from TitleDataReplicationDateTime t, DB_Title TLINNER JOIN Inserted I ON I.TitleReferenceNumber=LEFT(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,CHARINDEX(';',TL.DTI_SHORT_LEGAL_DISPLY_TEXT)-1) + 'CS'inner join TLon I.TitleReferenceNumber=TL.DTI_TITLE_REFRNC_NBRwhere LEN(TL.DTI_SHORT_LEGAL_DISPLY_TEXT )-LEN(REPLACE(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,';',''))=1But now when the trigger fires I get the following error:Msg 208, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 17Invalid object name 'TL'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 10:20:39
|
quote: Originally posted by Jessica I had to change it to this to get it to compile:Update tsett.TitleDataReceiveDateTime=getdate()from TitleDataReplicationDateTime t, DB_Title TLINNER JOIN Inserted I ON I.TitleReferenceNumber=LEFT(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,CHARINDEX(';',TL.DTI_SHORT_LEGAL_DISPLY_TEXT)-1) + 'CS'inner join DB_Title TLon I.TitleReferenceNumber=TL.DTI_TITLE_REFRNC_NBRwhere LEN(TL.DTI_SHORT_LEGAL_DISPLY_TEXT )-LEN(REPLACE(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,';',''))=1But now when the trigger fires I get the following error:Msg 208, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 17Invalid object name 'TL'.
you missed table name |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-10 : 10:29:03
|
| I changed it as you suggested and get the following:Msg 1011, Level 16, State 1, Procedure trTitle_LastDocumentChangeDate_IU_LastDocumentChangeDate, Line 20The correlation name 'TL' is specified multiple times in a FROM clause. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 10:34:05
|
dont duplicate aliasesUpdate tsett.TitleDataReceiveDateTime=getdate()from TitleDataReplicationDateTime t, DB_Title TLINNER JOIN Inserted I ON I.TitleReferenceNumber=LEFT(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,CHARINDEX(';',TL.DTI_SHORT_LEGAL_DISPLY_TEXT)-1) + 'CS'inner join DB_Title TL1on I.TitleReferenceNumber=TL1.DTI_TITLE_REFRNC_NBRwhere LEN(TL.DTI_SHORT_LEGAL_DISPLY_TEXT )-LEN(REPLACE(TL.DTI_SHORT_LEGAL_DISPLY_TEXT,';',''))=1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 10:39:38
|
| b/w how is TitleDataReplicationDateTime related to other tables? also why are you using DB_Title twice? |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-10 : 10:54:23
|
| I ended up changing it as follows and now it seems to work:BEGIN SET NOCOUNT ON UPDATE TitleDataReplicationDateTime SET TitleDataReceiveDateTime = GETDATE() FROM TitleDataReplicationDateTime D INNER JOIN Inserted I ON D.TitleReferenceNumber = I.TitleReferenceNumber INNER JOIN DB_Title T ON I.TitleReferenceNumber = T.DTI_TITLE_REFRNC_NBR WHERE T.DTI_SHORT_LEGAL_DISPLY_TEXT LIKE '%;%' AND T.DTI_SHORT_LEGAL_DISPLY_TEXT NOT LIKE '%;%;%' AND D.TitleReferenceNumber like SUBSTRING(T.DTI_SHORT_LEGAL_DISPLY_TEXT, 1, CHARINDEX(';', T.DTI_SHORT_LEGAL_DISPLY_TEXT) - 1) + 'CS' + '%' END |
 |
|
|
Jessica
Starting Member
23 Posts |
Posted - 2008-12-10 : 12:59:44
|
| Sorry...another question on this one...How would I add a case statment to the Where so that the clause I have specified is only evaluated in the case where there is a ; in DTI_SHORT_LEGAL_DISPLY_TEXT. In the case where ; is not in this field, the where clause should be ignored. Please let me know. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 21:15:44
|
| [code]UPDATE TitleDataReplicationDateTimeSET TitleDataReceiveDateTime = GETDATE()FROM TitleDataReplicationDateTime DINNER JOIN Inserted ION D.TitleReferenceNumber = I.TitleReferenceNumberINNER JOIN DB_Title TON I.TitleReferenceNumber = T.DTI_TITLE_REFRNC_NBRWHERET.DTI_SHORT_LEGAL_DISPLY_TEXT LIKE '%;%'AND T.DTI_SHORT_LEGAL_DISPLY_TEXT NOT LIKE '%;%;%'AND D.TitleReferenceNumber like SUBSTRING(T.DTI_SHORT_LEGAL_DISPLY_TEXT, 1,CHARINDEX(';',T.DTI_SHORT_LEGAL_DISPLY_TEXT)- 1) + 'CS' + '%'OR CHARINDEX(';',T.DTI_SHORT_LEGAL_DISPLY_TEXT)=0[/code] |
 |
|
|
|