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 |
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2008-08-20 : 10:07:19
|
| I want to write a trigger to do the following issue,I have a table called Events with fields Id, CustomerId(numeric),TagName(varchar),SmsBody(varchar),GID(int)and I have another table called Contacts with fields Id, CustomerId(numeric),MobileNumber,GID(int) and one more table called outbox with fields Id,CustomerId,TagName(varchar),SmsBody(varchar),MobileNumber(varchar)In the contacts table I have some records likeId<>CustomerId<>MobileNumber<>GID1<><><>100<><><>91xxxxxxxx<><><>31<><><>100<><><>91xxxxxxxx<><><>31<><><>100<><><>91xxxxxxxx<><><>21<><><>100<><><>91xxxxxxxx<><><>3etcNow if one record is inserted into Events table.Then Events table will look like thisId<>CustomerId<>TagName<>SmsBody<>GID1<><><><>100<><><>Test<><>Test msg<><>3After this record insertion trigger will get the mobile numbers from Contacts table where customerId = 1 and GID = 3 and it will insert into outbox table. Then outbox table will look like this:Id<>CustomerId<>TagName<>SmsBody<>MobileNumber1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxx1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxx1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxxhow to do a trigger for this one please? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-20 : 10:12:43
|
| If i remember correctly, i've given a similar solution to you before. Why are you still posting same question? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
rajuneo
Starting Member
3 Posts |
Posted - 2008-08-20 : 10:38:05
|
| I hope the following trigger solves ur problem.CREATE TRIGGER events_outbox_trigger ON Events_Table AFTER INSERTAS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; INSERT INTO Outbox_Table(custid, tagname, smsbody, mobilenum) SELECT et.custid, tagname, smsbody, mobilenum FROM Contacts_Table ct INNER JOIN inserted et ON ct.custid=et.custid AND ct.gid=et.gid -- Insert statements for trigger hereEND |
 |
|
|
|
|
|
|
|