×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Trigger not working with Join?

Trigger not working with Join?

Trigger not working with Join?

(OP)
Here is my trigger and it works great, However, I want to join a table called dbo.CustomerAddressBase and grab the accountbase.accountnumber and insert it into the table customeraddress.CFSMASCustNum, can I do this with one trigger? Can you Join 2 tables in a trigger? Below is my trigger, and then I wanted to add the bottom to it, but it doesn't work.

CREATE TRIGGER [mas_trigger] ON [dbo].[AccountBase]
FOR INSERT
AS
insert dbo.AR1_CustomerMaster
(Division, CustomerNumber,CustomerName,TermsCode, SalesPersonCode,
EmailAddress,URLAddress,PhoneNumber,FaxNumber,CreditLimit, ContactCode)

select
Case
when CFPDivision = 2 then '00' when CFPDivision = 3 then '10' when CFPDivision = 4 then '20'
when CFPDivision = 5 then '30' when CFPDivision = 6 then '40' when CFPDivision = 7 then '50'
When CFPDivision = 8 then '60' when CFPDivision = 9 then '70' when CFPDivision = 10 then '80'
when CFPDivision = 11 then '90'
end,
AccountNumber,[Name],
case
when PaymentTermsCode = 5 then '00' when PaymentTermsCode = 6 then '01'
when PaymentTermsCode = 7 then '02' when PaymentTermsCode = 8 then '03'
when PaymentTermsCode = 9 then '04' when PaymentTermsCode = 10 then '10'
when PaymentTermsCode = 11 then '15' when PaymentTermsCode = 12 then '20'
when PaymentTermsCode = 13 then '25' when PaymentTermsCode = 14 then '30'
when PaymentTermsCode = 15 then '98' when PaymentTermsCode = 16 then '99'
end,
CFSMAS200Salesperson,EMailAddress1,WebSiteURL,Telephone1,Fax,CreditLimit,CFSMASContactCode
from inserted

insert dbo.CustomerAddressBase
(CFSMASCustNum)
select
AccountNumber
from inserted
Join dbo.CustomerAddressBase

This is where it is failing.. Any Help?

RE: Trigger not working with Join?

Joining  dbo.CustomerAddressBase on what ? Usually, you should add this after
select
AccountNumber
from inserted
Join dbo.CustomerAddressBase
on inserted.<key field>=dbo.CustomerAddress.<key field>

HTH

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources