[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

insert trigger 2

Hi,
I'm getting an error with the following trigger. Please help!
ERROR: Incorrect syntax near '='.
Thanks

Create Trigger FSP_fullname
 on members_mike
 for insert
AS
SET FullName_ = ISNULL(rtrim(ltrim(ISNULL(FSP_First_Name, '')) + SPACE(1) + ltrim(ISNULL(FSP_SurName, ''))),'READER')
FROM members_mike t
      JOIN inserted i ON
          t.memberid_ = i.Imemberid_
where members_mike.memberid_ = inserted.memberid_
0
mandmtech
Asked:
mandmtech
  • 2
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Create Trigger FSP_fullname
 on members_mike
 for insert
AS
SELECT FullName_ = ISNULL(rtrim(ltrim(ISNULL(FSP_First_Name, '')) + SPACE(1) + ltrim(ISNULL(FSP_SurName, ''))),'READER')
FROM members_mike t
      JOIN inserted i ON
          t.memberid_ = i.Imemberid_
where members_mike.memberid_ = inserted.memberid_
0
 
mandmtechAuthor Commented:
Sorry but I'm an SQL rookie. So in this case the SELECT will act as an SET, meaning it will update the fullname_ column??
Thanks
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Okay , so u wanna update the  'Fullname'



Create Trigger FSP_fullname
 on members_mike
 for insert
AS
UPDATE t
SET FullName_ = ISNULL(rtrim(ltrim(ISNULL(FSP_First_Name, '')) + SPACE(1) + ltrim(ISNULL(FSP_SurName, ''))),'READER')
FROM members_mike t
      JOIN inserted i ON
          t.memberid_ = i.Imemberid_
where members_mike.memberid_ = inserted.memberid_

go
before testing do backup the database

0
 
twoboatsCommented:
"So in this case the SELECT will act as an SET"

Yes, you can't SET from a table, you have to select
0
 
mandmtechAuthor Commented:
Sorry, I missed the UPDATE
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now