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-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 12342 blablasslsls 5678 5678i 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 1234IF 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.. ThxSteve |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2006-01-03 : 18:35:44
|
May not need a trigger:declare @row_count intupdate YourTableset comment = comment + @new_commentwhere portimaid = @portimaid set @row_count = @@rowcountif @row_count = 0 begin insert into YourTable ...end-- ORif exists (select * from YourTable where portimaid = @portimaid)begin update YourTable set comment = comment + @new_commentend elsebegin insert into YourTable ...end Nathan Skerl |
 |
|
|
|
|
|