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 Trigger

Author  Topic 

stevo_3
Starting Member

20 Posts

Posted - 2006-01-03 : 14:15:30
Hello evryone,

i'm a quite newbie with SQL so this is my question:

i got a workitem table with several fields including id(key) comment(nvarchar) and portimaid(SUBSTR(20,25).

FOR EXAMPLE:
id(key) comment(nvarchar) portimaid(SUBSTR(20,25)
1 blablablabla 1234 1234
2 blablasslsls 5678 5678

i want to create a trigger that before he is inserting a record looks if the record is got the same portimaid and when he does
he needs to add the comment to the existing record
otherwise he need to create a new record in the database


FOR Example i want to add a record (and sow add the comment)
comment(nvarchar) portimaid(SUBSTR(20,25)
globglobsdfs 1234 1234

IF the portimaid is not the same as the existing records i want to create a new record in my table...

Does anyone got an idea for this case, i've started with a trigger but i'm really stuck..

Thx

Steve



nathans
Aged Yak Warrior

938 Posts

Posted - 2006-01-03 : 18:35:44
May not need a trigger:

declare @row_count int
update YourTable
set comment = comment + @new_comment
where portimaid = @portimaid
set @row_count = @@rowcount

if @row_count = 0
begin
insert into YourTable
...
end

-- OR

if exists (select * from YourTable where portimaid = @portimaid)
begin
update YourTable
set comment = comment + @new_comment
end else
begin
insert into YourTable
...
end




Nathan Skerl
Go to Top of Page
   

- Advertisement -