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
 General SQL Server Forums
 New to SQL Server Programming
 Trigger

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 like
Id<>CustomerId<>MobileNumber<>GID
1<><><>100<><><>91xxxxxxxx<><><>3
1<><><>100<><><>91xxxxxxxx<><><>3
1<><><>100<><><>91xxxxxxxx<><><>2
1<><><>100<><><>91xxxxxxxx<><><>3
etc


Now if one record is inserted into Events table.
Then Events table will look like this
Id<>CustomerId<>TagName<>SmsBody<>GID
1<><><><>100<><><>Test<><>Test msg<><>3

After 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<>MobileNumber
1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxx
1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxx
1<><><><>100<><><>Test<><>Test msg<><>91xxxxxxxxx

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 10:16:13
is this similar to below ones?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=106967
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=106909
Go to Top of Page

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 INSERT
AS
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 here

END
Go to Top of Page
   

- Advertisement -