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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Question about adding/updating records

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:

fields
id, contact_id, comments, portimaid, title, ,officeid,...
example data
1 , 22 , blabla , 2222 , Ticket:Open;2222;bl,1234,.....

trigger on my table
CREATE TRIGGER [testeke] ON [dbo].[workitem]
FOR INSERT, UPDATE
AS

UPDATE workitem
SET portimaid = SUBSTRING(title, 36, 6)
===========>the portimaid is a part of the title formed with the
function substring


what 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 Update
So 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 ignore

Second thing---------------------------------------
IF not all this above conditions he just need to add a new record in my workitem database


My question is this a realistic thought or can i solve this otherwise?
Anybody has ideas?

Many Thanks
Steve

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.
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -