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-06 : 14:02:48
|
Hello,i got a question about:i got a tableworkitem; with folowing fields:fieldsid, contact_id, comments, portimaid, title, ,officeid,...example data1 , 22 , blabla , 2222 , Ticket:Open;2222;bl,1234,.....trigger on my tableCREATE TRIGGER [testeke] ON [dbo].[workitem] FOR INSERT, UPDATEASUPDATE workitemSET portimaid = SUBSTRING(title, 36, 6)===========>the portimaid is a part of the title formed with the function substringwhat i want:First thing------------------------------i want that is possible to update an existing record,for example the folowwing record for my table workitem:contact_id, comments, portimaid, title, ,officeid,...22 , lalalala , 2222 , Ticket:Update;2222;bl,1234,.....like you can see the portimaid is the same (2222) AND in the title he needs to detect UpdateSo he needs to update the existing record (with the unique portimaid(2222)) and just add the commments (wich is lalalala) on the existing comment (blablabla), the rest of the record he need to ignoreSecond thing---------------------------------------IF not all this above conditions he just need to add a new record in my workitem databaseMy question is this a realistic thought or can i solve this otherwise?Anybody has ideas?Many ThanksSteve |
|
|
druer
Constraint Violating Yak Guru
314 Posts |
Posted - 2006-01-06 : 16:04:29
|
| You can use an "if exists (select whatever from table where criteria matches whatever)" command to find out of the record you want is already in the table, and if it is then you can do the update, otherwise do the insert. |
 |
|
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-07 : 03:19:01
|
Thanks for the quick answer, druer,my problem is that i don't know the command to insert the record or to update it,and like you see my database is populated with a trigger so i don'y know this has an impact on my table Steve |
 |
|
|
|
|
|
|
|