Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-05 : 03:41:32
|
Hello folks,here is my trigger:CREATE TRIGGER [testeke] ON [dbo].[workitem] FOR INSERT, UPDATEAS UPDATE workitemSET ticketstatus= SUBSTRING(title, 14,6)UPDATE workitemSET portimaid = SUBSTRING(title, 36, 6)UPDATE workitemSET officeid = SUBSTRING(title, 58, 9)UPDATE workitemSET contact_id=contact.id FROM contactWHERE EXISTS(SELECT officeid FROM workitem WHERE contact.external_id = officeid)And its about a title he needs to check, title is the field in the workitem table... He needs to look if he doesn't find 'Update' or 'Lost' (used substring see upstairs :) this is saved to an existing workitem row in the field "ticketstatus"i have had some example code to do this but i don't succeed to put it together:Example code that i had:declare @row_count intupdate workitemset comment = comment + @new_commentwhere portimaid = @portimaid set @row_count = @@rowcountif @row_count = 0 begin insert into YourTable ...endOR---------if exists (select * from YourTable where portimaid = @portimaid)begin update YourTable set comment = comment + @new_commentend elsebegin insert into YourTable ...endDoes anyone has an idea |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-05 : 06:46:38
|
Sorry i wasn't very clear indeed,i'm going to post the structure of my database,i got 2 tables; one trigger on the worktitem table1. Workitem: id(key), title, portimaid, officeid, contactid (wich is the same as the id from contact), comment,...2. Contact: id(key), external_id (wich is updated in the trigger and is the same as the officeidNow what i want to do:before a record is added into the table each workitem:he needs to check the field title, for example a title can be: Portima:Open; officeid=324234-01;... ORUpdated; officeid=324234-01;...,now if the title contains 'Updated' as string he needs to update an existing record in the database workitem, he needs to append the comment in an existing record of workitemif the title contains 'Open' he needs to add a new record in the databasehope it is a bit clear now,if not please reply, ThxSteve |
 |
|
|
|
|
|
|
|