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 |
|
capooti
Starting Member
4 Posts |
Posted - 2002-04-11 : 06:16:10
|
| Hi AllLet's suppose I have the following table:Fields: PersonIDNameMoneyDescriptionI want a trigger that automatically insert a description when you insert a new record or more new records at a time.The appropriate description depends on the money amount.It should be something like that:create trigger triInsertDescription on tablename for insertasupdate tablename if money < 20 then set tablename.description = 'poor' if money >= 20 and money < 50 then set tablename.description = 'medium' if money >= 50 then set tablename.description = 'medium' from tablename inner join inserted on tablename.PersonID = inserted.PersonID It can be inserted one record at a time, but also n records can be inserted from other tables.Someone would be so kind to tell me how to do this?Thanks in advance! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-04-11 : 07:50:39
|
| This will work:CREATE TRIGGER triInsertDescription ON tablename FOR INSERTAS UPDATE TSET description = CASE WHEN T.money < 20 then 'poor'WHEN T.money BETWEEN 20 and 50 then 'medium' WHEN T.money > 50 THEN 'medium' --should this be changed???FROM tablename TINNER JOIN inserted ION T.PersonID = I.PersonID |
 |
|
|
capooti
Starting Member
4 Posts |
Posted - 2002-04-11 : 08:17:05
|
| Thank you very much Rob, for the sample code.Obviously is missing the END statment, but the rest is perfect, you helped me a lotbye! |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-04-11 : 08:21:25
|
Need....new....eyeglasses...Glad it worked despite my efforts to ruin it |
 |
|
|
capooti
Starting Member
4 Posts |
Posted - 2002-04-11 : 08:23:56
|
Buy Rey Ban, they are pretty goood!!! quote:
Need....new....eyeglasses...Glad it worked despite my efforts to ruin it
|
 |
|
|
|
|
|